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
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:
@echo off
setlocal EnableDelayedExpansion
for /f %%v in ('wmic logicaldisk get freespace ^| findstr /r "[0-9]"') do (
set val=%%v
set val=!val:~-6!
set /a sum+=val
)
echo !sum!
endlocal
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).