Microsoft® System Center Configuration Manager 2007 Administrator’s Companion (Perfect Paperback)
by Steven D. Kaczmarek
Perfect Paperback: 850 pages
Publisher: Microsoft Press (January 30, 2008)
Language: English
ISBN-10: 0735623856
ISBN-13: 978-0735623859
Book link to Amazon
Mastering System Center Configuration Manager 2007 (Paperback)
by Brad Price and Jason Rutherford
Paperback: 888 pages
Publisher: Sybex; Pap/Onl edition (January 22, 2008)
Language: English
ISBN-10: 047017367X
ISBN-13: 978-0470173671
Book link to Amazon
The other day I got a question if they could delete files in a folder older then 7 days automaticlly. I solved the question with a script and a scheduled task. And I thought id share the script with you. I would like to thank Fredrik Wall for script review.
‘This is a script to delete files older then specified days
Option Explicit
Dim oFSO
Dim sDirectoryPath
Dim oFolder
Dim oFileCollection
Dim oFile
Dim iDaysOld
‘iDaysold = NumberofDays
iDaysOld = 7
‘sDirectoryPath = “Folder to deleteFiles in”
sDirectoryPath = “C:Tempforanexample”
On Error Resume Next
Set oFSO = CreateObject(“Scripting.FileSystemObject”)
If objFSO.FolderExists(sDirectoryPath) Then
Set oFolder = oFSO.GetFolder(sDirectoryPath)
Set oFileCollection = oFolder.Files
For each oFile in oFileCollection
If oFile.DateLastModified < (Date() – iDaysOld) Then
oFile.Delete(True)
End If
Next
else
WScript.Echo “No Folder”
End If
Set oFSO = Nothing
Set oFolder = Nothing
Set oFileCollection = Nothing
Set oFile = Nothing