amd64lover Posted January 5, 2006 Posted January 5, 2006 I have a folder of backups. Each backup is a .rar file. To conserve space, i would like a batch program that deletes all the files (there are only rar files in there) in the Backup folder that are older than 30 days. Does anyone know how to do this? I would prefer it to be a .bat file so i wouldnt have to install any extra software and could set it to run automatically using task scheduler... Thanks!Title Edited - Please follow new posting rules from now on.--Zxian
cluberti Posted January 5, 2006 Posted January 5, 2006 Be careful with this - there's no error checking. It'll go into a directory and delete all files that are older than 30 days without warning!Option Expliciton error resume next Dim objFSO Dim sDirectoryPath Dim objFolder Dim objFileCollection Dim objFile Dim iDaysOld'Set the number of days to go back iDaysOld = 30 Set objFSO = CreateObject("Scripting.FileSystemObject")'The sDirectoryPath can be a local folder or a \\server\share sDirectoryPath = "\\MyServer\MyFolder" set objFolder = objFSO.GetFolder(sDirectoryPath) set objFileCollection = objFolder.Files'If any file is older than iDaysOld value, then delete it. For each objFile in objFileCollection If objFile.DateLastModified < (Date() - iDaysOld) Then objFile.Delete(True) End If Next'Finish up Set objFSO = Nothing Set objFolder = Nothing Set objFileCollection = Nothing Set objFile = Nothing
Doc Symbiosis Posted January 5, 2006 Posted January 5, 2006 Perhaps this is a first step: This command lists the date of the file and the file names. No you just have to add the check for the date it delete the file or folder.In the variable %i the date is contained and in the vatiable %l the filename, %j contains the time of the fileceation and %k contains either "<DIR>", if it's a directory, or the filesize.for /f "tokens=1,2,3*" %i in ('dir /OD') DO echo %i %lIf you're using this in a batch, you have to set double '%' instead of one.
amd64lover Posted January 5, 2006 Author Posted January 5, 2006 thanks to both of you!@clubertiis that a batch file or vbs file? do i have to make a file for each folder that i wanted cleaned of files that are older than 30 days? its not a big deal, i only plan on using it for one folder anyways.
jftuga Posted January 5, 2006 Posted January 5, 2006 Try delen -- del enhanced. It should do the trick.http://www.geocities.com/jadoxa/delenxrd/-John
amd64lover Posted January 6, 2006 Author Posted January 6, 2006 @clubertigreat thanks!@jftugai was checking out delen and was using it to delete the contents of my backup folder (C:\Buildsof\Backups), but i have yet to figuer out a way to do this without deleting the folder itself. The command i am using is 'c:\buildsof\backups\ /sxy' .... i thought the last trailing backslash after the directory location would help, but it didnt.... any ideas?
amd64lover Posted January 6, 2006 Author Posted January 6, 2006 Actually, i just went ahead and added a mkdir command at the end of that so it would just recreate that folder... problem solved! thanks everyone
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now