Question : Need a batch file to delete files every day.

The below list of files gets created on a daily basis and I need help creating a script (batch) to delete these files at the start of the second day.  So the previous days files are deleted.  The problem is I have multiple files with different file names and types created in that folder and cannot delete these files.  The only files I need to delete are the ones listed below.

To Delete
20081114_BO14orderdepth.log
20081114_BO2order.log
20081114_CB16trade.log
20081114_BD2price.log
20081114_InitialQueries.log
20081117_BO1415order.log

Not to be deleted
6092_1120.txt
6190_1114.txt
6191_1118.txt
ReferencePoint (Folder)

The above files are also stored in the same directory and cannot be deleted

Answer : Need a batch file to delete files every day.

AmazingTech

The problem with this is your Today variable will not remain consistent. Dealing with dates via batch are a nightmare because there is not a true built-in feature to manipulate the format or output. Once the day is a single digit the output will not be correct, as it will include the / either in the month when it is 1-9, or the day when it is 1-9. Using the FORFILES to test the actual file creation date is solid as this will correctly determine the date of the file, and this is built in to the system. There are of course other utilities, or even vbscript that could accomplish this, but given that FOREFILES will do this in a one liner the extra confusion of dealing with formatting a date to match is not needed.


Random Solutions  
 
programming4us programming4us