I want to create a batch to check if the file have been modified to today's date, what i did was to "bring in a system's date and compare it with the modified date, if they match, then trigger something. My batch file works well and displays two right dates, but the IF statement saying the date mismatch.
@ECHO OFF
for /f "tokens=1,2,3,4 delims=. " %%i in ('date /t') do set date=%%k%%j
echo %date%
pause
FOR %%a IN (D:\MyFile.txt) DO SET FileDate=%%~ta
set DATEONLY=%FileDate:~0,10%
echo %DATEONLY%
pause
if DATEONLY==date (
echo date ok
)
else (
cls
ECHO Wrong
)
PAUSE
Here is a completely different approach:
The
forfiles
command is capable of checking the file date. In the above command line, it:.
),MyFile.txt
(of course there is onlyone),+0
days after today,/C
switch.If
MyFile.txt
has been modified today (or even in future), the given command line is executed; if it has been modified earlier than today, an error message is displayed andERRORLEVEL
is set to1
.Notice that
forfiles
is not a built-in command and might not be available on your operating system.