RE: delete files in a folder that are certain days old

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Exactly. Using the "NOW" command will specify today's date/time/etc..., this
will happen.

ESP

"WILDPACKET" wrote:

> 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.
> > >
.



Relevant Pages

  • Re: delete files in a folder that are certain days old
    ... "Rob Moerland" wrote: ... > ESP wrote: ... > I was looking for the answer a week ago and found FORFILES on my W2k3 ... > Maybe a .CMD script or a .vbs script using Runis the easy way. ...
    (microsoft.public.scripting.vbscript)
  • RE: Find SP2 - [WILDPACKET]
    ... I am not the scripting guy, ok, I will run this script after making the ... "ESP" wrote: ... > Set objRecordSet = objCommand.Execute ...
    (microsoft.public.scripting.vbscript)
  • RE: delete files in a folder that are certain days old
    ... In my scenario I want to schedule the files to be deleted which are older ... ESP" wrote: ... I found this script on the net and I would like to ... >> 'Walk through each file in this folder collection. ...
    (microsoft.public.scripting.vbscript)
  • Re: ID IP Address of Cable Modem Hooked to Linksys Router
    ... However, that requires a username and password which is cumbersome, ... esp. ... hoping for a program that was already in circulation that would do this. ... put the router password in the script). ...
    (comp.dcom.modems.cable)
  • Re: Problems with Transfer
    ... I am not very familiar with ESP but it would be really interesting to find ... Since TAPI3 is just a COM layer that translates all calls to TAPI2 ... and all TSPs are behaving well with regards to this scenario ...
    (microsoft.public.win32.programmer.tapi)