1.

Solve : IF command to run new bat file?

Answer»

I am somewhat of a newbie at bat files, so I HOPE I can explain this clear enough.. I am trying to get another bat file to run if any file in a certain folder has been modified today. So basically , if "c:\*.doc" was modified today then run "modfile.bat" and if no "c:\*.doc" files where modified today then run "nofile.bat"

I am running windows XP if that makes any difference. Any help on this would be greatly appreciated.

Thanks,
Psycho DanIn a FOR loop, get each file modified date (the date shown by DIR) and compare it to the %date% system variable.


Thanks contrex...

This is what I have come up with, and it seems to work

for %%F in (*.doc) do (for /F %%D in ("%%~tF") do (set mdate=%%D))
for /F "tokens=2" %%D in ('date/t') do set cdate=%%D

if "%cdate%"=="%mdate%" start modfile.bat
if not "%cdate%"=="%mdate%" start nofile.bat

It will only find the last file in the folder (if there are more than one) because you have the loop that finds the files all on one line.

Also, why use date /t when you have %date% available to you?

Shouldn't you be LOOKING at the 1st token of %%~tF rather than of the OUTPUT of date /t ?

I don't know about your location, but where I am, (Europe) %date% is

30/09/2007

and %%~tF would have this format

30/09/2007 11:27





Discussion

No Comment Found