Drive information

In this chapter you will learn:

  1. DriveInfo: name, type, format and available free space

Get drive information

using System;/*from  java2  s  .c om*/
using System.IO;

static class MainClass
{
    static void Main(string[] args)
    {
        FileInfo file = new FileInfo("c:\\test.txt");

        // Display drive information.
        DriveInfo drv = new DriveInfo(file.FullName);

        Console.Write("Drive: ");
        Console.WriteLine(drv.Name);
        
        if (drv.IsReady)
        {
            Console.Write("Drive type: ");
            Console.WriteLine(drv.DriveType.ToString());
            Console.Write("Drive format: ");
            Console.WriteLine(drv.DriveFormat.ToString());
            Console.Write("Drive free space: ");
            Console.WriteLine(drv.AvailableFreeSpace.ToString());
        }

    }
}

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. Set File access rule
  2. Add file access rule
Home » C# Tutorial » File, Path
File creation
Deleting Files
Put to recycle bin
File Exists
File moving
File size
File attribute
Set file attribute
File time change
File time
Random file name
Temporary file
Path
Directory creation
Delete directory
Path existance
Change the path
Current Path
Directory listing
Recursive Path Listing
Combine path
Calculate Directory Size
Invalid path characters
System path
Directory copy
Drive
Drive information
File access rule
File System watcher