You can query the drives on a computer with the DriveInfo class:
using System;
using System.IO;
using System.Linq;
using System.Text;
class Program
{
static void Main()
{
DriveInfo c = new DriveInfo("C"); // Query the C: drive.
long totalSize = c.TotalSize; // Size in bytes.
long freeBytes = c.TotalFreeSpace; // Ignores disk quotas.
long freeToMe = c.AvailableFreeSpace; // Takes quotas into account.
foreach (DriveInfo d in DriveInfo.GetDrives()) // All defined drives.
{
Console.WriteLine(d.Name); // C:\
Console.WriteLine(d.DriveType); // Fixed
Console.WriteLine(d.RootDirectory); // C:\
if (d.IsReady)
{
Console.WriteLine(d.VolumeLabel);
Console.WriteLine(d.DriveFormat);
}
}
}
}
The output:
C:\
Fixed
C:\
NTFS
D:\
CDRom
...
...
The static GetDrives method returns all mapped drives, including CD-ROMs, media cards, and network connections.
DriveType is an enum with the following values:
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |