Determine the free space of a mounted volume?

L

LowFuel

Anyone know how I can determine the free space of a volume that is
mounted within a folder, rather than on a drive letter?

The DriveInfo class seems to want to work only off drive letters.

What I'm trying to do is write a simple program to generate a disk
space usage report. I have numerous volumes mounted as:

c:\storage\data1
c:\storage\data2
etc....

data1 and data2 above are volumes, not folders, and I want to determine
how much free space each has.

Thanks for any tips...

Jason
 
J

jeremiah johnson

WMI is what you need. I only have one disk mounted but this program
worked for me with the one disk:

using System;
using System.Collections;
using System.Text;
using System.Runtime.InteropServices;
using System.Management;

namespace WMITest {
class Program {
static void Main(string[] args) {

foreach(ManagementObject drive in
new ManagementObjectSearcher(
"select * from Win32_DiskDrive").Get()) {

// associate physical disks with partitions
foreach(ManagementObject partition in
new ManagementObjectSearcher(
"ASSOCIATORS OF {Win32_DiskDrive.DeviceID='"
+ drive["DeviceID"]
+ "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition").Get()) {

Console.WriteLine("Partition=" + partition["Name"]);

// associate partitions with logical disks (drive letter volumes)
foreach(ManagementObject disk in
new ManagementObjectSearcher(
"ASSOCIATORS OF {Win32_DiskPartition.DeviceID='"
+ partition["DeviceID"]
+ "'} WHERE AssocClass = Win32_LogicalDiskToPartition").Get()) {

Console.WriteLine("free space="
+ Convert.ToDouble(disk["FreeSpace"])
/ (1024 * 1024) + " Megs.");
}
}
}
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top