I made a cmd script to get the freespace of each drive in a PC and send an alert if under a value (the constant "MyLimit"). I found that the variables are not correctly evaluated in my "for" loop (the cycle within the list of drives)
This is the "for" loop:
Set MyLimit=107374182400
for /f "tokens=1-3" %%a in ('WMIC LOGICALDISK GET FreeSpace^,Name^,Size ^|FINDSTR /I /V "Name"') do (
if not "%%c"=="" (
echo FreeSpace=%%a
echo Name=%%b
echo Size=%%c
if %%a LSS %MyLimit% (
Echo not enough free space in %%b
) else (
echo "do nothing"
)
)
)
but the variable %%a always assumes the value of the last index of the "for" loop... then the IF always fails...
Where is the error?
Thanks for your support
Ale
I tried your suggestions, see below, but still it doesn't work maybe I put some error inside the code, I'm not so sure to have well done:
@Echo off
SETLOCAL enabledelayedexpansion
Set GB100=107374182400
Set TB_10=10995116277760
Set MyLimit=%TB_10%
for /f "tokens=1-3" %%a in ('WMIC LOGICALDISK GET FreeSpace^,Name^,Size ^|FINDSTR /I /V "Name"') do (
if not "%%c"=="" (
echo FreeSpace=%%a
echo Name=%%b
echo Size=%%c
call :padNum %%a
call :padNum MyLimit
echo %%a
echo %MyLimit%
if "%%a" LSS "%MyLimit%" (
Echo not enough free space in %%b
) else (
echo "nothing"
)
)
)
:padNum
setlocal enableDelayedExpansion
set "n=000000000000000!%~1!"
set "n=!n:~-15!"
endlocal & set "%~1=%n%"
exit /b
I intentionally put a high limit (10TB) to force the message...