Hello all,
I am using the below script to delete files based on creation date but I can not get it to work. For example, I want to delete a file that is 30 minutes old. I eventually want it for 24 hours but I am trying to test it by using a smaller interval. Here is the script:
Dim fso, startFolder, OlderThanDate
Set fso = CreateObject("Scripting.FileSystemObject")
startFolder = "C:\Test\"
DeleteOldFiles startFolder
Function DeleteOldFiles(folderName)
Dim folder, file, fileCollection, folderCollection, subFolder
Set folder = fso.GetFolder(folderName)
Set fileCollection = folder.Files
For Each file In fileCollection
If DateDiff("n", Now, file.DateCreated) < -30 Then
fso.DeleteFile(file.Path)
End If
Next
End Function
Right now the script deletes everything. I can't figure out what I have done. Any help would be greatly appreciated.
I am using the below script to delete files based on creation date but I can not get it to work. For example, I want to delete a file that is 30 minutes old. I eventually want it for 24 hours but I am trying to test it by using a smaller interval. Here is the script:
Dim fso, startFolder, OlderThanDate
Set fso = CreateObject("Scripting.FileSystemObject")
startFolder = "C:\Test\"
DeleteOldFiles startFolder
Function DeleteOldFiles(folderName)
Dim folder, file, fileCollection, folderCollection, subFolder
Set folder = fso.GetFolder(folderName)
Set fileCollection = folder.Files
For Each file In fileCollection
If DateDiff("n", Now, file.DateCreated) < -30 Then
fso.DeleteFile(file.Path)
End If
Next
End Function
Right now the script deletes everything. I can't figure out what I have done. Any help would be greatly appreciated.