Solved

Code to loop through and check last modified date

Posted on 2011-09-12
4
213 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
  • 2
4 Comments
 
LVL 16

Expert Comment

by:carsRST
Comment Utility
   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
Comment Utility
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 31

Assisted Solution

by:Rob Henson
Rob Henson earned 166 total points
Comment Utility
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 51

Assisted Solution

by:Bill Prew
Bill Prew earned 167 total points
Comment Utility
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
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…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now