How to

get drives

Published: 13. December 2008 | Updated: 13. December 2008
License: Microsoft Public License (MS-PL)
Categories: File system, Windows » Hardware
Tags: C# File System Hardware Windows
Was this snippet helpful for you? YESYES / NONO
Get Analyzant!

Check your entire website from code to content in minutes with Analyzant, the free analysis suite.

Free download at analyzant.com

Snippet example shows how to get drives in the computer (hdd, cd, dvd etc.)

Import namespaces

using System.IO;

Code

DriveInfo[] drives = DriveInfo.GetDrives();
foreach (DriveInfo drive in drives)
{
    Console.Write("{0} {1}", drive.Name, drive.DriveType);
    if (drive.IsReady)
    {
        Console.Write(" {0} {1}/{2}", drive.VolumeLabel, drive.TotalFreeSpace, drive.TotalSize);
    }
    Console.WriteLine();
}
Console Output:
A:\ Removable
C:\ Fixed  96172195840/107364544512
D:\ CDRom BRMEFPP_EN 0/596588544
Send us feedback about this snippet »



Related Snippets: