How can I get the list of logial drives (C#) on a system as well as their capacity and free space?
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.
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.
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.
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.
System.IO.DriveInfo.GetDrives()
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); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With