?
Solved

Code to loop through and check last modified date

Posted on 2011-09-12
4
Medium Priority
?
256 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 668 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 664 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 56

Assisted Solution

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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa‚Ķ

800 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