I need a bat file to get C:\ drive total space and free space available in GB (giga bytes) in a Windows system and create a text file with the details.
Note: i dont want to use any external utilities.
I need a bat file to get C:\ drive total space and free space available in GB (giga bytes) in a Windows system and create a text file with the details.
Note: i dont want to use any external utilities.
Not a complete solution by any means, but someone might find this helpful:
This is probably not at all what you want since it uses PowerShell, but "external utilities" is a bit nebulous and leaves me some wiggle room. Plus, it's essentially a one-liner.
Since batch/CMD is bad at nearly everything, I decided to use PowerShell, which is meant for such stuff and has quick and easy access to WMI.
Here's the PowerShell code:
This spits out the two values separated by a comma. Now, if only we could do this in a FOR loop!
PowerShell has the nice ability to accept a Base64-encoded command (to eliminate the need for escaping and making the code hard to read), so all we need to do is shrink this command as much as possible (to reduce the size of the encoded string—strictly a nicety, not absolutely necessary). I also reduced the sizes to integers, which rounded them. It's at least closer than discarding the lower-order decimal digits.
Shrinking the encoded command and encoding it in PowerShell looks like this:
(See PowerShell /? for more details.)
I would expect this to run on any Win7 or Win8 machine in existence. The PoSH code doesn't rely on any advanced features (except maybe the EncodedCommand bit), so if PoSH is installed on the XP or Vista machine, there's a good chance of it working. I can't speak about the history of MS pushing PoSH via Windows Update, but I think there's a good chance that this will work ubiquitously.
This should work in batch:
cut 9 digits of the size by bytes to get the size in GB:
cmd can calculate only with numbers up to
2^31-1
(2,147,483,647 ~ 2.000001 Gigabytes)