This is a script I’ve had running for a while, it currently deletes old files from my ftp server when they have been there for 14 days or more. It also checks subfolders.
Set objArgs = WScript.Arguments
set fso = createobject(“scripting.filesystemobject”)
set folders = fso.getfolder(FolderName)
datetoday = now()
newdate = dateadd(“d”, Days*-1, datetoday)
wscript.echo “Today:” & now()
wscript.echo “Started deleting files older than :” & newdate
wscript.echo “Completed deleting files older than :” & newdate
sub recurse( byref folders)
set subfolders = folders.subfolders
set files = folders.files
wscript.echo “Deleting Files under the Folder:” & folders.path
for each file in files
if file.datelastmodified < newdate then
wscript.echo “Deleting ” & folders.path & “\” & file.name & ” last modified: ” & file.datelastmodified
on error resume next
for each folder in subfolders
set subfolders = nothing
set files = nothing
Then just call it passing in the directory and the number max file age in number of days.
cscript myscript.vbs c:\files 7
I should have mentioned, if you are on Windows server, you can use File Server Resource Manager (FSRM) to do this, it’s much neater.