I'm trying to get integer of free disk space in Batch file. This is a my (very) simple code.
@echo off
wmic logicaldisk get freespace >> freespace.log
exit
But output in freespace.log file.
FreeSpace
9772687360
57401442304
7346626560
0
0
I need to pick integer only and summation. After summation output like this.
74520756224
I search on Google as my best but I can't find solutions. Please help me:)
Use below code. Try replacing the
caption
text withdeviceid
if it shows?
or blank.Here is a pure batch solution that can handle numbers greater than ~ 2G:
Here is an exact solution using hybrid batch and powershell. It really should be done with pure powershell, vbscript, or jscript.
The non-intuitive use of tokens and the IF statement are to compensate for the weird interaction between FOR /F and the unicode output of WMIC.
I second @dbenham's recommendation to switch to PowerShell (or at least VBScript or JScript). However, if you want to stick with batch and don't need exact numbers you could do something like this:
The line
set val=!val:~-6!
removes the last 6 digits from each value. That way you can calculate with Megabytes instead of Bytes, but (obviously) lose some precision, because the value is truncated (and not rounded correctly).