How to delete folders older than x days
Hello All,
found a way to delete files older than x days with "forfiles" command. Is there a way to instruct forfiles to delete a folder older than x days too. Or alternatively is there a way to delete via batch file folders older than x days
Thank you and best regards
giuseppe
giuseppe
August 30th, 2010 3:51pm
You can .vbs file:
iDaysOld = x
Set oFSO = CreateObject("Scripting.FileSystemObject")
sDirectoryPath = "C:\Temp"
set oFolder = oFSO.GetFolder(sDirectoryPath)
set oFileCollection = oFolder.Files
'If database log file backups are older than x days, delete them.
For each oFile in oFileCollection
If oFile.DateLastModified < (Date() - iDaysOld) Then
oFile.Delete(True)
End If
Next
'Clean up
Set oFSO = Nothing
Set oFolder = Nothing
Set oFileCollection = Nothing
Set oFile = Nothing
I have found it in this link, so you can have a look at it:
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_23094977.html
Best regards.
Free Windows Admin Tool Kit Click here and download it now
August 30th, 2010 4:02pm
I found another script:
http://forums.devshed.com/windows-help-34/deleting-files-older-than-14-days-using-batch-file-script-364137.html
As it is a script related question, you can also create a post to
The Official Scripting Guys Forum! Forum
http://social.technet.microsoft.com/Forums/en/ITCG/threadsShaon Shan| TechNet Subscriber Support in forum| If you have any feedback on our support, please contact tngfb@microsoft.com
September 1st, 2010 11:41am