How do I get free space on a drive volume without a letter?
I am trying to find information on free volumes. Those with letters are exact (GetDiskFreeSpaceEx). I also connected to VDS (Virtual Disk Service) and got something called Available AllocationUnits ( A) and AllocationUnitSize (B) where A * B = free size as shown by Windows. But B is 4096, so it is not an exact number in bytes.
- How can you determine this without VDS?
- Is there a more accurate way (in bytes)?
Regards,
Kate
+3
source to share
1 answer
On Windows, you can run the following commands and parse the output:
vssadmin list volumes
This gives:
C:\Windows\system32>vssadmin list volumes
vssadmin 1.1 - Volume Shadow Copy Service administrative command-line tool
(C) Copyright 2001-2013 Microsoft Corp.
Volume path: \\?\Volume{66c6160d-60cc-11e3-824b-806e6f6e6963}\
Volume name: \\?\Volume{66c6160d-60cc-11e3-824b-806e6f6e6963}\
Volume path: D:\
Volume name: \\?\Volume{66c6160f-60cc-11e3-824b-806e6f6e6963}\
Volume path: C:\
Volume name: \\?\Volume{66c6160e-60cc-11e3-824b-806e6f6e6963}\
Then run
fsutil volume diskfree
What gives:
C:\Users\MC>fsutil volume diskfree \\?\Volume{66c6160e-60cc-11e3-824b-806e6f6e6963}\
Total # of free bytes : 47826694144
Total # of bytes : 255691059200
Total # of avail free bytes : 47826694144
To read the output of a shell process, you can read the standard output
string output = proc.StandardOutput.ReadToEnd();
DISCLAIMER: Yes, I know this is not the cleanest way, but it is the way. As I don't know an API to access such low level information.
+1
source to share