1.

Solve : Can a bat file know the date??

Answer»

I have a bat file that runs via Windows Scheduler every Sunday at 2 am. I'd like to add another command in the bat file to delete some log files, but I don't won't to do this every week - just once a month. Yes, I could set up another TASK, but I'd prefer to add the logic in the bat file itself so that this line only runs once a month. Can anyone help?!Yes, batch files are aware of the date thru the %date% variable (XP and Win2000), thru the PROMPT statement or thru the date command.

You would need to setup a control file that holds the last month run, extract the current month from the current date, do a compare and then decide whether to run the delete or not and if you do, update the control file accordingly. This could get ugly.

In general batch files do not do arithmetic, and date calculations would be a nightmare. VB Script has many date functions that could help you out. Script would be a wiser choice.

That said, why reinvent the wheel? The Task Scheduler was designed for just this purpose. Always USE the best tool for the job.

Hope this helps.



Discussion

No Comment Found