Get Total disk space free/used?!

  • Thread starter Thread starter Lars Siden
  • Start date Start date
L

Lars Siden

Hi,

Searched the .Net docs over and over again....are there no functions to get
the Disk Total Size and Total Free space etc? Do I have to use the old and
ugly GetFreeDiskEX from win32Api?

Best regards,

Lazze
 
Hi,

I think that is GetDiskFreeSpaceEx?

If WMI is installed, you could reference System.Management.dll assembly.
Here is a quick sample that will dump the info you require for each logical
disk to the console, from here you can play with the query, search for
Win32_LogicalDisk in the MSDN for all the information that can be extracted.

ManagementObjectSearcher searcher = new ManagementObjectSearcher(
"select * from Win32_LogicalDisk where DriveType=3" );

foreach ( ManagementObject disk in searcher.Get() )
{
Console.WriteLine("Disk {0} - Size {1}, Free {2}",
disk["Name"], disk["Size"], disk["FreeSpace"]);
}

Hope this helps

Chris Taylor
 
Back
Top