I want to check if the C: drive has at least a certain amount of storage left (in this case 60GB) and halt the execution if it doesn't. But I am stuck with CMD telling me that 160000 is less than 60000 and I can't figure out why.
This is the code:
@echo off & setlocal enableextensions enabledelayedexpansion
:: If disk space is less than this value, script will not be executed
SET DISK_SPACE_ERROR_AMOUNT_MB=60000
FOR /f "tokens=3" %%i IN ('dir /-c^|findstr /c:"bytes free"') DO SET "Free=%%i"
:: Free contains the bytes of storage left
SET /A DiskFreeKB=%Free:~,-3%
SET /A DiskFreeMB=%DiskFreeKB%/1024
echo Disk Space Check:
echo %DiskFreeKB% KB
echo %DiskFreeMB% MB
echo Err amount %DISK_SPACE_ERROR_AMOUNT_MB%
IF "%DiskFreeMB%" LSS %DISK_SPACE_ERROR_AMOUNT_MB% (
:: DiskFreeMB less than error amount
echo.
echo ERROR
echo Not enough space left - %DiskFreeMB% MB of the required minimum of %DISK_SPACE_ERROR_AMOUNT_MB% MB
echo ERROR
echo.
PAUSE
EXIT 1
) ELSE (
echo Disk space is ok
:: (Continue with other code)
)