The following script is supposed to check if the number of files and folders has changed since the last time the batch-file was run. If so, it prints a message and updates the counts.
Unfortunately it doesn't quite work. I think I have a problem with the
if statements in my string comparisons.
Does anyone know how I can get the script to work?
@echo off ::Check number of dir's and files in last run set /p filecounta=<"countfile.log" set /p dircounta=<"countdir.log" ::Check number number of dir's and files currently for /f %%A in ('dir /a-d-s-h /b ^| find /v /c ""') do set filecountb=%%A for /d %%G in (*) do set /a dircountb=dircountb+1 ::Compares the number of counts in the past with the present if not "%filecountb%"=="%filecounta%" goto :news if not "%dircountb%"=="%dircounta%" goto :news CALL :save echo no news pause exit :news CALL :save echo news pause exit :: Subs :: Put number of dir and files in log file :save echo %filecountb% >"countfile.log" echo %dircountb% >"countdir.log" GOTO:EOF
After @Rik's suggestion I tried removing the space before
echo %filecountb%>"countfile.log" and
echo %dircountb%>"countdir.log" but that didn't work in my OS. The solution was adding a
TRIM-function to remove the spaces after reading them from the log-files.
::Check number of dir's and files in last run set /p filecounta=<"countfile.log" set /p dircounta=<"countdir.log" CALL :TRIM %filecounta% filecounta CALL :TRIM %dircounta% dircounta . . . :TRIM SET %2=%1 GOTO :EOF