Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a list of logical drives

Tags:

c#

hard-drive

How can I get the list of logial drives (C#) on a system as well as their capacity and free space?

like image 592
PaulB Avatar asked Apr 23 '09 14:04

PaulB


People also ask

How can I get a list of available drives?

Click on the Start menu, type CMD in the search box, then right-click on it and select Run as administrator. Or press WIN + R, type CMD, and press Enter. Type diskpart in CMD to start it. Step 2: Type list disk and press Enter.

How do I get a list of drives in Command Prompt?

Right-click on "Command Prompt" and choose "Run as Administrator". At the prompt, type "diskpart" and hit Enter. At the diskpart prompt type "list disk". This will list all the hard drives in the system.

How many logical disks does my computer have?

On a single physical drive, you can configure up to 24 logical drives. For a computer with one physical drive with C: drive as its first logical drive, you can configure up to 23 additional logical drives on that drive's extended partition if also configured.

How can I see all the drives connected?

To view all your connected drives, head to Settings > System > Storage and scroll down and click the “View storage usage on other devices” link under the “More storage settings” section. On the next page, you will see other connected devices like USB flash drives and other internal or external secondary data drives.


2 Answers

System.IO.DriveInfo.GetDrives()

like image 182
Richard Avatar answered Oct 03 '22 23:10

Richard


foreach (var drive in DriveInfo.GetDrives()) {     double freeSpace = drive.TotalFreeSpace;     double totalSpace = drive.TotalSize;     double percentFree = (freeSpace / totalSpace) * 100;     float num = (float)percentFree;      Console.WriteLine("Drive:{0} With {1} % free", drive.Name, num);     Console.WriteLine("Space Remaining:{0}", drive.AvailableFreeSpace);     Console.WriteLine("Percent Free Space:{0}", percentFree);     Console.WriteLine("Space used:{0}", drive.TotalSize);     Console.WriteLine("Type: {0}", drive.DriveType); } 
like image 28
Chris Ballance Avatar answered Oct 04 '22 00:10

Chris Ballance