Remove files older than X days


Nedenstående VBScript sletter alle filer og sub-foldere indenfor de sidste 7 dage.

Dim objFile,colFileCollection
Set objFSO =
CreateObject(“Scripting.FileSystemObject”)
Set objFolder = objFSO.GetFolder(“C:MyTest”)
Set colSubfolders = objFolder.Subfolders
For
Each ObjSubFolder In colSubfolders
Set objTargetFolder = objFSO.GetFolder(“C:MyTest”)
Set colTargetSubfolders = objTargetFolder.Subfolders
Set colFileCollection = objFolder.Files
For
Each ObjTargetSubFolder In colTargetSubfolders
If
DateAdd(“d”, –7, Now()) > ObjTargetSubFolder.dateCreated Then
ObjTargetSubFolder.Delete True
End If
Next
Next

Et andet eksempel kunne være at benytte komandoen FORFILES, som kommer med windows 2003.

FORFILES /p C:Backup-file /s /m *.* /d -7 /c “CMD /C del /Q @FILE”

For mere info se nedenstående link.
http://forums.webhostautomation.com/showpost.php?s=b2301a35427e72673ac5ab14fcf828dd&p=129664&postcount=1

Et sidste eksempel kunne være at benytte PowerShell.
http://myitforum.com/cs2/blogs/yli628/archive/2007/10/02/powershell-script-to-delete-files-older-than-certain-days.aspx

Comments are closed.