how to delete folders and files older than 14 days old

  • Thread starter Thread starter Eric
  • Start date Start date
E

Eric

I have been asked by our engineering dept to automatically delete all
files folders and subfolders older than 14 days old located in our FTP
folder on a windows 2000 server. I have seen several threads about
this but don't have the skills to create a program to do this.

Is there any software out here that will do this task? If not is
there a way someone could walk me through creating a script to do
this?

Thanks,
Eric
 
Try this great (free) tool
it si GUI based and Command line based (therfor can be put in a simple command file and f.i. scheduled every day)

http://www.savilltech.com/download.html

DelOld, version 2003 Been around for years. this latest version reads "beta" but is robust rock solid.
"A great utility to remove files matching a certain age and specification"

gr,
Erwin
 
Eric,

I had to do the same exact thing about 2 months ago. Below is a script
that will take care of it. The only thing you should need to change is
the "dir" variable which is the "root" directory which houses your FTP
files. The scan is recursive so it will also get any files in any of
the subfolders under the root directory.

If you need any help with it let me know and I'll do what I can.

Regards,
SWBradbury

-----------------------------

'This script scans through the FTP folders and deletes all files older
than 14 days.
'Process began on June 1st, 2004
'Written by SWBradbury

Option Explicit
' Create the FileSystem Object
dim oFileSys
dim dir
'Directory to be scanned
dir = "D:\FTPfiles"

Set oFileSys = CreateObject("Scripting.FileSystemObject")

'Start up Sub
GetDir dir

sub GetDir(dir)
dim oFolder,oFolders,oFiles,item,Item2

set oFolder=oFileSys.GetFolder(dir)
set oFolders=oFolder.SubFolders
set oFiles=oFolder.Files

' get all sub-folders in this folder
For each item in oFolders
GetDir(item)
Next
item2=0

'Scan through the files collection, find files older than 14 days,
and delete.
For each item2 in oFiles
Dim accessDate,createdate,fDateInfo,DaysOld
Set fDateInfo = oFileSys.GetFile(item2)
createdate = fDateInfo.DateCreated
accessDate = fDateInfo.DateLastAccessed
DaysOld = DateDiff("d", accessDate, Now)

If DaysOld > 14 Then
item2.delete
end if

next

end sub
 
SWBradbury said:
Eric,

I had to do the same exact thing about 2 months ago. Below is a script
that will take care of it. The only thing you should need to change is
the "dir" variable which is the "root" directory which houses your FTP
files. The scan is recursive so it will also get any files in any of
the subfolders under the root directory.

[snip first part of code]

'Scan through the files collection, find files older than 14 days,
and delete.
For each item2 in oFiles
Dim accessDate,createdate,fDateInfo,DaysOld
Set fDateInfo = oFileSys.GetFile(item2)
createdate = fDateInfo.DateCreated
accessDate = fDateInfo.DateLastAccessed
DaysOld = DateDiff("d", accessDate, Now)

If DaysOld > 14 Then
item2.delete
end if

next
Hi

Note that when deleting files, you should *never* do this when still
looping in the file collection returned from the File System Object
(FSO). The collection may get mixed up with unpredictable results.
E.g. create an array of the file paths first to avoid this.

In the article below there is a WSH script (vbscript) by Michael
Harris that deletes files x days old in a specific folder (and
optionally all subfolders), using an array of the file paths.

Newsgroups: microsoft.public.scripting.wsh
Date: 2002-10-07 08:12:33 PST
http://groups.google.com/[email protected]
 
I have used a program called GNDEL. It seems to work pretty good. You
can get it from WWW.Reg.net.

SWBradbury said:
Eric,

I had to do the same exact thing about 2 months ago. Below is a script
that will take care of it. The only thing you should need to change is
the "dir" variable which is the "root" directory which houses your FTP
files. The scan is recursive so it will also get any files in any of
the subfolders under the root directory.

[snip first part of code]

'Scan through the files collection, find files older than 14 days,
and delete.
For each item2 in oFiles
Dim accessDate,createdate,fDateInfo,DaysOld
Set fDateInfo = oFileSys.GetFile(item2)
createdate = fDateInfo.DateCreated
accessDate = fDateInfo.DateLastAccessed
DaysOld = DateDiff("d", accessDate, Now)

If DaysOld > 14 Then
item2.delete
end if

next
Hi

Note that when deleting files, you should *never* do this when still
looping in the file collection returned from the File System Object
(FSO). The collection may get mixed up with unpredictable results.
E.g. create an array of the file paths first to avoid this.

In the article below there is a WSH script (vbscript) by Michael
Harris that deletes files x days old in a specific folder (and
optionally all subfolders), using an array of the file paths.

Newsgroups: microsoft.public.scripting.wsh
Date: 2002-10-07 08:12:33 PST
http://groups.google.com/[email protected]



--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx
 
Back
Top