Solved

Code to loop through and check last modified date

Posted on 2011-09-12
4
253 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 55

Assisted Solution

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

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

726 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