Solved

Code to loop through and check last modified date

Posted on 2011-09-12
4
248 Views
Last Modified: 2012-05-12
Thinking about trying to make something that will help keep a server clean and up to date.  I am looking for some VBA Code that will look through all the folder and files in a directory, and if the last modified date is greater than 7 days ago, I would like to list out the file path in an excel sheet.....

any thoughts?

-Brandon
0
Comment
Question by:KnutsonBM
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 16

Expert Comment

by:carsRST
ID: 36523954
   Dim fileitem As File
    Dim fso
    Set fso = New Scripting.FileSystemObject
    Set SourceFolder = fso.GetFolder("c:\temp\")

    For Each fileitem In SourceFolder.Files
        If Right(fileitem.Path, 4) = ".xls" And Right(fileitem.Path, 12) <> "Comments.xlsx" Then
               
            If DateDiff("d", fileitem.DateLastModified, Now) > 7 Then
                 ActiveSheet.Cells(Range("A1").End(xlDown).Row, 1) = fileitem.Path
            End If
        End If
       
    Next
0
 
LVL 16

Accepted Solution

by:
carsRST earned 167 total points
ID: 36524024
Sorry - took some code from a few places...didn't clean up properly.

Adjusted...


    Dim strPath As String
    strPath = "c:\temp\"
   
    Dim fileitem As File
    Dim fso
    Set fso = New Scripting.FileSystemObject
    Set SourceFolder = fso.GetFolder(strPath)

   
    For Each fileitem In SourceFolder.Files
        If Right(fileitem.Path, 4) = ".xls" Or Right(fileitem.Path, 5) = ".xlsx" Then

                Row = ActiveSheet.Range("A1").Range("A65536").End(xlUp).Row + 1
           
            If DateDiff("d", fileitem.DateLastModified, Now) > 7 Then
                 ActiveSheet.Cells(Row, 1) = fileitem.Path
            End If
        End If
       
    Next
0
 
LVL 33

Assisted Solution

by:Rob Henson
Rob Henson earned 166 total points
ID: 36524134
There is a good old fashioned DOS routine that you can run that will extract contents of a directory and its sub-directories and export them to a text file.

The parameters that can be added to the statement include size and filetype so no doubt they can include modified date.

It is based on the DIR command but I cannot remember the exact parameters.

I will start investigating.

Thanks
Rob H
0
 
LVL 54

Assisted Solution

by:Bill Prew
Bill Prew earned 167 total points
ID: 36524330
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question