Tuesday, June 29, 2010

List Partitions / Devices

With C# easily all available hard drives can be listed. Logical partitions on a physical hard drive are treated as independant devices.
The following console application shows the use of the class DriveInfo (System.IO has to be included) to get the names of all available devices on the computer:
            DriveInfo[] Drives = DriveInfo.GetDrives();

            foreach (DriveInfo drive in Drives)
            {
                Console.WriteLine(drive.Name);
            }
On my computer the program outputs "C:\, D:\, E:\". First ones are partitions on my hard disk, the last one is the CD ROM drive.

No comments:

Post a Comment