Is it possible to programatically find the free space available in mapped drives?
How to find the percentage of free space in your drive using ms-dos.
It may be easy to find the free space for a drive in ur hard disc but i need to find the free-space of mapped drives.
I have mapped some file servers in my systems.
It is possible to see this in My Computer, but how do show it in a command prompt?
(Taken from an old answer of mine over at Server Fault)
The easiest way to reliably get at the free disk space is using WMI. When trying to parse the output of
diryou get all kinds of funny problems, at the very least with versions of Windows in other languages. You can usewmicto query the free space on a drive:This will output something like
You can force this into a single line by adding the
/format:valueswitch:There are a few empty lines there, though (around three or four) which don’t lend themselves well for processing. Luckily the
forcommand can remove them for us when we do tokenizing:The nice thing here is that since we’re only using the second token all empty lines (that don’t have a second token) get ignored.
Remember to double the
%signs when using this in a batch file:You can now use the free space which is stored in the environment variable
%FreeSpace%.Getting percentages now is a little tricky since batch files only support 32-bit integers for calculation. However, you probably don’t need to calculate this to the byte; I think megabytes are quite enough:
This should work unless your volumes get larger than 20 TiB.