i want create batch check if file have been modified today's date, did "bring in system's date , compare modified date, if match, trigger something. batch file works , displays 2 right dates, if statement saying date mismatch.
@echo off /f "tokens=1,2,3,4 delims=. " %%i in ('date /t') set date=%%k%%j echo %date% pause %%a in (d:\myfile.txt) set filedate=%%~ta set dateonly=%filedate:~0,10% echo %dateonly% pause if dateonly==date ( echo date ok ) else ( cls echo wrong ) pause
there following problems:
- do not use variable name
datebuilt-in variable containing current date (typeset /?help); - the first
forstatement useless, because%date%available; - the strings
dateonly,datecompared literally inifstatement, need state%dateonly%==%date%instead; - the
elsestatement must in same line closing parenthesis ofifbody (typeif /?help);
so try this:
@echo off echo %date% pause %%a in (d:\myfile.txt) set filedate=%%~ta set dateonly=%filedate:~0,10% echo %dateonly% pause if %dateonly%==%date% ( echo date ok ) else ( echo wrong ) pause note: regard dates in batch file locale-dependent.
Comments
Post a Comment