|
-
October 5th, 2005, 03:23 AM
#1
Drive Space!
does anyone know what i would use to get the free space on my local hard drive.
I am looking for something that I can pass the drive letter into.
something that would work like this... (i know this is not actuall code just givving an example of how i would expect it to function)
intFreeSpace = localmachine.drivespace.freespace(driveletter);
Thanks in Advance,
David
-
October 5th, 2005, 03:52 AM
#2
Re: Drive Space!
You could do something like this:
Code:
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("Free space {0}\n", GetDiskSpace("c:"));
}
static UInt64 GetDiskSpace(string drive)
{
// make it upper
drive = drive.ToUpper();
// enumerate disks
ManagementClass pDiskClass = new ManagementClass("Win32_LogicalDisk");
ManagementObjectCollection pDisks = pDiskClass.GetInstances();
foreach (ManagementObject pDisk in pDisks)
if (drive.CompareTo((string)pDisk["name"]) == 0)
return (UInt64) pDisk["FreeSpace"];
// disk not found
return 0;
}
- petter
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|