I wrote a script to grab the list for folders from a file and it will check and delete for files that are more than 90 days old.
The script was able to delete the files older than 90 days. However I keep on getting an error saying:
D:\cleanup90days.vbs(25, 3) Microsoft VBScript runtime error: Invalid procedure call or argument
I don't have an idea what I have missed. Any help will be appreciated.
Below is my script:
Dim days
Dim inputFolderList, ObjFolder, Files, objFileAge
If Not WScript.Arguments.Count = 2 Then
Wscript.Echo "Invalid number of arguments. Arg1: Daily or Weekly. Arg2: Remove all files older then this"
WScript.Quit(-1)
End If
days = WScript.Arguments.Item(1)
inputFileList = "D:\FileGrep2.txt"
Set Fso = CreateObject("Scripting.FileSystemObject")
Set objTextFile = fso.OpenTextFile(inputFileList, 1)
Do Until objTextFile.AtEndOfStream
sFolderName = objTextFile.ReadLine
getfoldernames(sFolderName)
Loop
Function getfoldernames(sFolderName)
Set ObjFolder = fso.GetFolder(sFolderName)
Set Files = ObjFolder.Files
For Each Check In Files
objFileAge = DateDiff("n", Check.DateLastModified, Now)
If objFileAge > 90 Then
WScript.Echo Now & "the following will be deleted " & Check.Path
Check.Delete
End If
Next
End Function