Re: Any way to automatically delete old files from the FTP Directory? by Scooter
Scooter
Mon Jul 28 11:30:16 CDT 2008
Oh and if you need to skip any particular extensions, here's an
update. You change "re.Pattern" to exclude the extensions you want to
skip, seperating each with a pipe symbol as in the example:
If Wscript.Arguments.Count = 0 Then
Wscript.Echo "You need to tell me the directory"
Else
FileSearch Wscript.Arguments(0)
End If
Sub FileSearch(InDir)
Set fso = CreateObject("Scripting.FileSystemObject")
Set fileObject = fso.GetFolder(InDir)
Set fileCollection = fileObject.Files
Set subfoldersCollection = fileObject.SubFolders
Set re = new regexp
For Each fInfo In fileCollection
thisFileName = InDir & "\" & fInfo.Name
wscript.echo thisFileName
re.IgnoreCase = true
' Add your extensions to skip here
re.Pattern = "config|cfg|dll|exe"
thisFileType = Right(thisFileName,Len(thisFileName)-
InStrRev(thisFileName,"."))
If re.Test(thisFileType) Then
'Skip This File
wscript.echo "Skipping " & thisFileName
Else
Set thisFile = fso.GetFile(thisFileName)
createdate = thisFile.DateCreated
lastModifiedDate = thisFile.DateLastModified
' Do you want 90 days since creation, or 90 days since last
modified?
'intDaysOld = cInt(Date - CreateDate)
intDaysOld = cInt(Date - lastModifiedDate)
If intDaysOld > 90 Then
wscript.echo thisFileName & " is " & intDaysOld & " days old.
Deleting!"
'fso.DeleteFile(thisFileName)
End If
End If
Next
'' If you want it to go into subdirectories, uncomment below
'For Each fFolder In subfoldersCollection
' FileSearch (InDir & "\" & fFolder.Name)
'Next
End Sub