I need help with some logic or more.
My code is suppose to delete files in a folder if they are older then 7 days and they are not a file listed in files_keep.txt.
I need it to read through the files_keep.txt file and insure its not in there before it deletes the file. I don't want to read through the files_keep.txt file each time its looking to delete a file. So i thought i would read it into an array and then test againt the array to see if the file is listed before deleting. But couldn't figure out the logic to get this done.
code:
Path1 = "C:\jboss-3.2.5\server\all\log"
file_keep = "C:\temp\files_keep.txt"
Dim fso, oFolder, oFile, oSubFolder, file_to_keep
ret_time = 7 'retention time
Set fso = createobject("Scripting.FileSystemObject")
Set oFolder = fso.GetFolder(Path1)
Set f1=fspenTextFile(file_keep,1 )
MyArray = Split(f1.ReadAll, vbNewLine)
For Each oFile In oFolder.files
If DateDiff("d", oFile.datelastmodified,Now) > ret_time Then
If oFile <> Marray(iocount) Then
WScript.Echo "About to delete " & oFile
oFile.Delete True
End if
End If
Next
My code is suppose to delete files in a folder if they are older then 7 days and they are not a file listed in files_keep.txt.
I need it to read through the files_keep.txt file and insure its not in there before it deletes the file. I don't want to read through the files_keep.txt file each time its looking to delete a file. So i thought i would read it into an array and then test againt the array to see if the file is listed before deleting. But couldn't figure out the logic to get this done.
code:
Path1 = "C:\jboss-3.2.5\server\all\log"
file_keep = "C:\temp\files_keep.txt"
Dim fso, oFolder, oFile, oSubFolder, file_to_keep
ret_time = 7 'retention time
Set fso = createobject("Scripting.FileSystemObject")
Set oFolder = fso.GetFolder(Path1)
Set f1=fspenTextFile(file_keep,1 )
MyArray = Split(f1.ReadAll, vbNewLine)
For Each oFile In oFolder.files
If DateDiff("d", oFile.datelastmodified,Now) > ret_time Then
If oFile <> Marray(iocount) Then
WScript.Echo "About to delete " & oFile
oFile.Delete True
End if
End If
Next