Hey all,
First off, I am not a programmer but I need to create a script to delete files on one of our servers. I have a working script that will delete all files in a specific folder and all of it's subfolders after 30 days. I need to add some sort of a wildcard or exclusion for a few specific folders to delete the files after 90 days. I know normal wildcards don't work with the File System Object. Is there anything I can do to get this working? Thank you.
NumberOfDaysOld = 30
strPath = "C:\Test"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strPath)
Set colSubfolders = objFolder.Subfolders
Set colFiles = objFolder.Files
For Each objFile in colFiles
If objFile.DateLastModified < (Date() - NumberOfDaysOld) Then
objFile.Delete
End If
Next
For Each objSubfolder in colSubfolders
Set colFiles = objSubfolder.Files
For Each objFile in colFiles
If objFile.DateLastModified < (Date() - NumberOfDaysOld) Then
objFile.Delete
End If
Next
Next
First off, I am not a programmer but I need to create a script to delete files on one of our servers. I have a working script that will delete all files in a specific folder and all of it's subfolders after 30 days. I need to add some sort of a wildcard or exclusion for a few specific folders to delete the files after 90 days. I know normal wildcards don't work with the File System Object. Is there anything I can do to get this working? Thank you.
NumberOfDaysOld = 30
strPath = "C:\Test"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strPath)
Set colSubfolders = objFolder.Subfolders
Set colFiles = objFolder.Files
For Each objFile in colFiles
If objFile.DateLastModified < (Date() - NumberOfDaysOld) Then
objFile.Delete
End If
Next
For Each objSubfolder in colSubfolders
Set colFiles = objSubfolder.Files
For Each objFile in colFiles
If objFile.DateLastModified < (Date() - NumberOfDaysOld) Then
objFile.Delete
End If
Next
Next