Link to home
Start Free TrialLog in
Avatar of ammounpierre

asked on

Delete Files basedon a date parameter ?

I have an application that creates files with the following template "TR"+month (2digits)+4random digits..
I need a batch file that will delete the files of previous month....
so let's say we are in month 07...
I need to delete the files that are "TR06"+blabla...

I started from ..
set M=%DATE:~4,2%
Now I have the parameter ...but how to tell DOS to delete
"TR"+%M%+blabla ?

thanks a lot
Avatar of oBdA

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ammounpierre


Where do u find some help about the commands ? like set /a
what doesnt lastmonth=100 ? or 112 ??? could u please explain...
In line 3, I'm adding a 1 in front of the current date so that January is 101 instead of 01, because of the octal problem I described above.
Line 4 obviously subtracts 1 from the current month, and if the current month happens to be January (100), the month before is December (112).
Line 6 removes the 1 from the bginning again, because the data claculation is done.
The path in line 8 obviously needs to be adjusted to your target folder; a question mark in a file mask stands for any single character, so since you have 4 random characters at the end, you'll need 4 quesiton marks to cover those. If necessary, add the file extension as well.
Perfect !