Hi guys,
I've searched the web for a script that will do this, I've returned quite a lot of results including the following:
This script runs with no errors but doesn't touch any files - any ideas why?
I've searched the web for a script that will do this, I've returned quite a lot of results including the following:
Option Explicit
' Set constants for log file paths and maximum age of files
const LogPath1 = "e:\Cognos\Temp\test"
Const LogFileAge = 30
'WScript.Echo LogPath1
DeleteFilesByDate logpath1, LogFileAge
Sub DeleteFilesByDate(ByVal path, ByVal age)
' Deletes files over a certain age
Dim objFSO
Dim objFolder
Dim colFiles
Dim objFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(path)
Set colFiles = objFolder.Files
'WScript.Echo "More than " & age & " days old:"
For Each objFile In colFiles
' If file is over age then delete
If (objFile.DateCreated < Date - age) Then
'WScript.Echo "Deleting..."
'WScript.Echo objFile.Name & ": " & objFile.DateCreated
objFile.Delete
End If
Next
' Tidy up
Set objFSO = Nothing
Set objFolder = Nothing
Set colFiles = Nothing
End Sub
This script runs with no errors but doesn't touch any files - any ideas why?