Home All Groups Group Topic Archive Search About

Finding files older than 2 weeks old



Author
12 Nov 2007 5:23 PM
mharmon
I want to write a script that will look through a folder and subfolder and
find all files of a particular file extension that are over 2 weeks old and
write these files to a log.
Then run weekly from Windows Scheduler.

Author
12 Nov 2007 6:31 PM
McKirahan
Show quote
"mharmon" <mhar***@discussions.microsoft.com> wrote in message
news:F3A9BFF0-A0FF-494A-A8BF-2C6B01B01903@microsoft.com...
> I want to write a script that will look through a folder and subfolder and
> find all files of a particular file extension that are over 2 weeks old
and
> write these files to a log.
> Then run weekly from Windows Scheduler.
Author
12 Nov 2007 6:33 PM
McKirahan
Sorry for the last blank post.

"mharmon" <mhar***@discussions.microsoft.com> wrote in message
news:F3A9BFF0-A0FF-494A-A8BF-2C6B01B01903@microsoft.com...
> I want to write a script that will look through a folder and subfolder and
> find all files of a particular file extension that are over 2 weeks old
and
> write these files to a log.
> Then run weekly from Windows Scheduler.

Write the files (i.e. their contents) or filenames to a log file?
If the former then hopefully it's not binary data.  What extension?
Author
12 Nov 2007 6:50 PM
McKirahan
Show quote
"McKirahan" <N***@McKirahan.com> wrote in message
news:Q5CdnaM7BIDTAaXanZ2dnUVZ_sOrnZ2d@comcast.com...
> Sorry for the last blank post.
>
> "mharmon" <mhar***@discussions.microsoft.com> wrote in message
> news:F3A9BFF0-A0FF-494A-A8BF-2C6B01B01903@microsoft.com...
> > I want to write a script that will look through a folder and subfolder
and
> > find all files of a particular file extension that are over 2 weeks old
> and
> > write these files to a log.
> > Then run weekly from Windows Scheduler.
>
> Write the files (i.e. their contents) or filenames to a log file?
> If the former then hopefully it's not binary data.  What extension?


Will this help?  Watch for word-wrap.

This write the full path of files older than "cDAZ" to a log file.
Modify the value of "cFOL" to your folder.
Modify the value of "cTXT" to your extension.


    Option Explicit
   '*
   '*  Declare Constants
   '*
    Const cVBS = "oldfiles.vbs"
    Const cLOG = "oldfiles.log"
    Const cFOL = "D:\Temp"
    Const cEXT = ".txt"
    Const cDAZ = 14
   '*
   '*  Declare Variables
   '*
    Dim strDIR
        strDIR = WScript.ScriptFullName
        strDIR = Left(strDIR,InStrRev(strDIR,"\"))
    Dim dtmDLM
    Dim arrFIL()
    Dim intFIL
        intFIL = 0
    Dim strFIL
    Dim strFOL
    Dim dtmNOW
        dtmNOW = Now
   '*
   '*  Declare Objects
   '*
    Dim objFSO
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Dim objGFI
    Dim objOTF
    Set objOTF = objFSO.OpenTextFile(strDIR & cLOG,2,True)
   '*
   '*  GetFilesFolders()
   '*
    If objFSO.FolderExists(cFOL) Then
        Call GetFilesFolders(cFOL)
        For intFIL = 0 To UBound(arrFIL)
            objOTF.WriteLine arrFIL(intFIL)
        Next
    End If
   '*
   '*  Destroy Objects
   '*
    Set objOTF = Nothing
    Set objFSO = Nothing
   '*
   '*  Newset File
   '*
    WScript.Echo intFIL & " files older than " & cDAZ & " days."

Sub GetFilesFolders(folder)
   '*
   '*  Get Files
   '*
    For Each strFIL In objFSO.GetFolder(folder).Files
        If LCase(Right(strFIL.Name,Len(cEXT))) = cEXT Then
            Set objGFI = objFSO.GetFile(folder & "\" & strFIL.Name)
                dtmDLM = objGFI.DateLastModified
            Set objGFI = Nothing
            If DateDiff("d",dtmDLM,dtmNOW) > cDAZ Then
                ReDim Preserve arrFIL(intFIL)
                arrFIL(intFIL) = folder & "\" & strFIL.Name
                intFIL = intFIL + 1
            End If
        End If
    Next
   '*
   '*  Get Subfolders
   '*
    For Each strFOL In objFSO.GetFolder(folder).SubFolders
        Call GetFilesFolders(strFOL.Path)
    Next
End Sub
Author
13 Nov 2007 6:55 AM
Michael Bednarek
On Mon, 12 Nov 2007 09:23:02 -0800, mharmon
<mhar***@discussions.microsoft.com> wrote in
microsoft.public.windows.server.scripting:

>I want to write a script that will look through a folder and subfolder and
>find all files of a particular file extension that are over 2 weeks old and
>write these files to a log.
>Then run weekly from Windows Scheduler.

You need to define what constitutes "over 2 weeks old". Whatever that
is, it's trivial with the right CLI (4NT):
  DIR /s /b /[d-14,1980-01-01] d:\dir\*.ext >file.log
which considers the modification date.

4NT is a commercial program. I'm sure solutions in most other languages
are more elaborate.

--
Michael Bednarek  http://mbednarek.com/  "POST NO BILLS"

AddThis Social Bookmark Button