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

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



This would work great for what I need, however, when I run this command the
date selection (/dt-100 or /d t-100) doesn't work. If I put in an exact
date it works well, but I need it to delete all files older than 100 days,
and need to run it monthly without having to enter a new date every month.

To list all of the files older than 100 days on drive C:, type:
> forfiles /p c:\ /s /m*.* /dt-100 /c"cmd /c echo @file : date >= 100
> days"

Am I doing something wrong?


"Rob Moerland" wrote:

> ESP wrote:
> > 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.
> >>>>
> Hi,
>
> I was looking for the answer a week ago and found FORFILES on my W2k3
> server.
>
> It's part of the Resource Kit since Win98 and part of the OS in W2k3.
>
> Look at
> http://www.microsoft.com/technet/prodtechnol/windowsserver2003/library/ServerHelp/9660fea1-65c7-48cf-b466-204ba159381e.mspx
> to read:
>
> To list all of the files older than 100 days on drive C:, type:
> forfiles /p c:\ /s /m*.* /dt-100 /c"cmd /c echo @file : date >= 100
> days"
>
> Maybe a .CMD script or a .vbs script using Run() is the easy way.
>
> Greetings,
> Rob
>
.



Relevant Pages

  • Re: script error
    ... WMI services is up and running. ... If I run the script locally, ... After research I found the following regarding connecting to remote ... W2k3 can only connect to Win9x and NT if credentials supplied. ...
    (microsoft.public.scripting.vbscript)
  • Re: Listing / Exporting Security Group Membership
    ... If you have a W2K3 DC you can use dsget. ... to Script Center, you'll probably find a sample script you can use there. ... >I need to print out a list of members in a security group - text or Excel ...
    (microsoft.public.win2000.active_directory)
  • Best way to add multiple users
    ... batch of new accounts ... >have to be created from the enrolment spreadsheets. ... >A script was used in the past with NT but it does not ... work well with W2K3. ...
    (microsoft.public.windows.server.general)
  • 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: Selective Install Based on OS?
    ... You would need to place a test in the script, and exit if not W2k3. ... verbose to have so many divergences for OS. ...
    (microsoft.public.windows.group_policy)