We have a couple FTP servers here at my job and there are files which have been in these directories for years. The company policy stated that files older than 30 days must be deleted. Some people follow it and others don't. So I decided to help them out.
This script will clean out all files, NOT FOLDERS, under the specified directory where the date created is older than the maximum age in days specified.
----------COPY EVERYTHING BELOW THIS LINE----------
On Error Resume Next
'Start Script Configuration----------------------------------------------------------------------------
FolderName = "E:\FTPSite\"
Days = 30
dt = Replace(Date,"/","-")
'End Script Configuration------------------------------------------------------------------------------
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile( "C:\FTPCleanup"& dt &".log")
set fso = createobject("scripting.filesystemobject")
set folders = fso.getfolder(FolderName)
datetoday = now()
newdate = dateadd("d", Days*-1, datetoday)
There are 2 parts to this script, one is the cleanup configuration and the other is the Email configuration.
The first part you need to configure is the Cleanup settings.
FolderName = "E:\FTPSite\"
Replace "E:\FTPSite\" with the path to your FTP Root Directory
Days = 30
Replace 30 with how many days old you want to start deleting after
dt = Replace(Date,"/","-")
Dont touch this one, this one formats the date and time for the cleanup report
If you do not need this to send an email confirmation, simply delete from
'Start SMTP Configuration------------------------------------------------------------------------------
to the end of the script
If you do want to send the cleanup report to someone, simply fill in with your from, to, email subject, email body, and email server.
This script delete ONLY FILES, NOT FOLDERS. This script also only cares about files older than the time specified. It will delete ALL FILES that mean its criteria.
I also chose to go with date created because if you go off of modified date, if you take a file from 3 years ago and put it in the cleanup folder, it will get deleted the first time the script runs because the last time the file was modified was 3 years ago but when you copy it to a new server, a new Date created gets created.
This script is provided "AS IS" with no warranties expressed or implied.