T_Noble Posted January 19, 2010 Posted January 19, 2010 Hi All, Been working on another project. I am looking for a piece of code, to put in a .bat file, that does the following: *Filename* is stored like the following example "19-01-2010--14-51.sql" ---- Looks at the current date If C:\LoginTrackerBackups\*Filename* is 7 days or older than the current date DeleteFile Else Move onto the Next file End ---- Kind Regards Tom
tumbleweed Posted January 19, 2010 Posted January 19, 2010 It's not quite what you were talking about, but here's a few lines I used last week to get a backup job tidying up after itself ... net use Z: \DELETE net use Z: \\server\share forfiles /P Z: /M "*.BKF" /D -21 /C "CMD /C DEL @FILE"
T_Noble Posted January 20, 2010 Author Posted January 20, 2010 You should really store your filenames like "2010-10-29--14-15.sql", not "19-01-2010--14-51.sql" Even so, it's tricky to do the date arithmetic in a script, more so in a batch file. All is not lost, though. If the age of the file is correct, you can use ROBOCOPY, which makes short work of tasks like these. md c:\MyTemp robocopy.exe C:\LoginTrackerBackups C:\MyTemp /e /MOVE /MINAGE:7 * del /s /q /f c:\MyTemp This will move all files older than 7 days to MyTemp, then delete MyTemp. I am hoping that the MINAGE part is going to work. This is something I cannot test until this time next week, as I dont have a file in that folder that is more than a week old. Does it look at the File Modified Date attribute to work out if it is over a week old? Kind Regards Tom
Arthur Posted January 20, 2010 Posted January 20, 2010 The attached script should do it. Although it's a VBScript you can use CScript to run it in a batch file. Run 'cscript PurgeFiles.vbs /?' from a command prompt for help. Another alternative (if you don't mind relying on third-party programs) is DelOld.PurgeFiles.vbs
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now