RE: delete files in a folder that are certain days old
- From: "WILDPACKET" <WILDPACKET@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 8 Nov 2005 11:15:07 -0800
This article talks about deleting oldar than specified date.
In my scenario I want to schedule the files to be deleted which are older
than 2 days using a similar script.
ESP" wrote:
> The Scripting Guys have a nice lil' page on this. Very easy to follow :-)
>
> http://www.microsoft.com/technet/scriptcenter/resources/qanda/nov04/hey1104.mspx
>
>
> ESP
>
>
>
>
>
> "WILDPACKET" wrote:
>
> > I am nill with scripting. I found this script on the net and I would like to
> > delete files older than 2 days from a folder. Please correct this for me. I
> > really appreciate.
> >
> > Option Explicit
> > on error resume next
> > Dim oFSO
> > Dim sDirectoryPath
> > Dim oFolder
> > Dim oFileCollection
> > Dim oFile
> > Dim iDaysOld
> >
> > 'Customize values here to fit your needs
> > iDaysOld = 2
> > Set oFSO = CreateObject("Scripting.FileSystemObject")
> > sDirectoryPath = "FolderName here. Can be UNC path like \\MyServer\MyFolder"
> > set oFolder = oFSO.GetFolder(sDirectoryPath)
> > set oFileCollection = oFolder.Files
> >
> > 'Walk through each file in this folder collection.
> > 'If it is older than 3 weeks (21) days, then delete it.
> > For each oFile in oFileCollection
> > If oFile.DateLastModified < (Date() - iDaysOld) Then
> > oFile.Delete(True)
> > End If
> > Next
> >
> > 'Clean up
> > Set oFSO = Nothing
> > Set oFolder = Nothing
> > Set oFileCollection = Nothing
> > Set oFile = Nothing
> >
> >
> > Thank you very much in advance.
> >
.
- Follow-Ups:
- Prev by Date: Re: Controlling Internet Explorer
- Next by Date: Script to delay autologon
- Previous by thread: Re: How to extract line from text file
- Next by thread: RE: delete files in a folder that are certain days old
- Index(es):
Relevant Pages
|