I am trying to write a batch script to detect for missing files from a list of files on Windows. Given the format of the file names to be "day_month_date_hh_mm_00_yyyy.enf", and the hours of the files will be different, I have to identify if there's a file of a particular hour is missing. I have written down the following to find out the number of days in a given year and month.
set /p m="Enter month: "
set /p y="Enter year: "
REM call :DaysOfMonth %y% %m%
setlocal DisableDelayedExpansion
set /a "yy = %y%, mm = 100%m% %% 100"
set /a "n = 30 + !(((mm & 9) + 6) %% 7) + !(mm ^ 2) * (!(yy %% 4) - !(yy %% 100) + !(yy %% 400) - 2)"
set maxDay=%n%
echo Days Of Month: %maxDay%
However, I have no idea how to generate the Day of a date when I run the loop to check for missing files. I have search abit on the net and combined a few codes which will definitely not work as I am still very new to batch. Below is the part of the script where I am stuck at and need help on.
for /L %%d in (1,1,%maxDay%) do (
for /L %%f in (0,1,%max%) do (
if %%f < 10 (
set hour=0%%f
) else (
set hour=%%f
)
set "num=%%Day_%m%_%%d_%hour%_00_00_%y%"
if not exist "num.enf" (
echo num.enf
set /A "cnt=!cnt!+1"
)
)
)
NUMBER MISSING: !cnt!
The full script is as per below:
@echo off
set max=24
set cnt=0
set /p m="Enter month: "
set /p y="Enter year: "
setlocal DisableDelayedExpansion
set /a "yy = %y%, mm = 100%m% %% 100"
set /a "n = 30 + !(((mm & 9) + 6) %% 7) + !(mm ^ 2) * (!(yy %% 4) - !(yy %% 100) + !(yy %% 400) - 2)"
set maxDay=%n%
echo Days Of Month: %maxDay%
setlocal ENABLEDELAYEDEXPANSION
pause
for /L %%d in (1,1,%maxDay%) do (
for /L %%f in (0,1,%max%) do (
if %%f < 10 (
set hour=0%%f
) else (
set hour=%%f
)
set "num=%%Day_%m%_%%d_%hour%_00_00_%y%"
if not exist "num.enf" (
echo num.enf
set /A "cnt=!cnt!+1"
)
)
)
NUMBER MISSING: !cnt!
endlocal &exit /b %n%
Please help advise me how do I rectify the errors in the script and how to generate the day of the specified date in the loop to identify missing file. Thanks in advance!
day_month_date_hh_mm_00_yyyy.enfis itfri_July_17_10_39_00_2020.enf?Get-Date "15/07/2020 00:00" -format "ddd"