I'm a bit new to the whole bat files, but Google is my friend

Nonetheless I'm encountering a problem I can not find on Google, so hopefully you can help me out.
In the script below, I have a counter running to count the amount of missing files in a folder. The counter it self works, because the total is correct. However when I display the number it always shows 0 (with echo).
Does someone know why this happens and more preferably how I can avoid it and display the right number

Code: Select all
@echo off
::DATE+TIME
set mydate=%date:~-4,4%%date:~-7,2%%date:~-10,2%
for /f "tokens=1-2 delims=/:" %%a in ('time /t') do (set mytime=%%a%%b)
::LOG FILE NAME
SET LOGFILE=E:\compare_log_%mydate%_%mytime%.txt
echo ---------------------------------------- >> %LOGFILE%
echo Compare LocationCode (E) with ScanIn (C) >> %LOGFILE%
echo Date: %mydate% %mytime% >> %LOGFILE%
echo ---------------------------------------- >> %LOGFILE%
SET DEST=C:\DEST
SET SRC=E:\SOURCE
SET /A COUNT=0
SET /A LOCCOUNT=0
:: Notify user of action
echo ----------------------------------------
echo Compare SOURCE (E) with DEST (C)
echo Date: %mydate% %mytime%
echo ----------------------------------------
echo Scanning all folders and files in
echo %SRC%
echo for the existence of the log file in
echo %DEST%
echo This proces takes a few seconds
cd %SRC%
for /f "usebackq delims=|" %%f in (`dir /b %SRC%`) do (
cd %SRC%\%%f
SET /A LOCCOUNT=0
echo LocationCode: %%f >> %LOGFILE%
for %%x in (*.log) do (
if NOT exist %DEST%\%%x (
echo Missing: %%x >> %LOGFILE%
set /a LOCCOUNT+=1
)
)
set /a COUNT+=LOCCOUNT
echo %%f : %LOCCOUNT%
echo ---------------------------------------- >> %LOGFILE%
)
cd ..
echo --------------##FINISED##--------------- >> %LOGFILE%
echo Total: %COUNT% >> %LOGFILE%
echo ---------------------------------------- >> %LOGFILE%
echo ----------------------------------------
echo ----------##Process finished##----------
echo Total: %COUNT%
echo Logfile: %LOGFILE%
echo ----------------------------------------
PAUSE
LocationCode is a result from the dirname