I have done some basic testing on revised script on the code provided
earlier. This VB code will allow you to specify the folder, file
extension, and date.
FYI you will need to save the file as a VBS and the run it from the
command like this:
wscript filename.vbs
or like
cscript filename.vbs
Dim fso, f, f1, fc
Dim temp, pos
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder("c:\test") 'Gets the folder
Set fc = f.Files 'gets all of the files in the folder, makes a
collection
For Each f1 in fc 'increments through each of the files in fc
temp = f1.name 'get file name
temp=right(temp,4) 'get the last 4 characters in the string (match
this to the number of characters in the if statement (.txt = 4)
if(temp = ".txt" AND DateDiff("d", f1.DateLastModified, Now) >
15) then 'only delete if it is the correct file type and so old
f1.delete
end if
Next
Set fso = Nothing
Set f = Nothing
Set fc = Nothing
|