I need to  report on what files have not been accessed in last 90 days (VBS below) and record the directory and subdirectories and files that fall into this category

Posted on 2006-04-04
Last Modified: 2010-04-17
Please ignore the move statement.. All i need to do is report on what files have not been accessed in last 90 days and record the directory and subdirectories and files that fall into this category, any ideas would be great....

' Declaration of objects
Dim FSO, f, fld, fls, vSourceDir, vArchiveDir

' Setting data directories
 vSourceDir = "d:\data\"
 vArchiveDir = "d:\Archive\"
 'Setting Log file to d:\...."Date script run.txt"
 datelogfile = "d:\ArchiveLog\" & CStr(Replace(FormatDateTime(Now, vbShortDate), "/", "-", 1, -1, 1)) & ".txt"
 ' Set obejcts standard VBs
 Set fst = CreateObject("Scripting.FileSystemObject")
 Set flog = fst.CreateTextFile(datelogfile, True)
 Set FSO = CreateObject("scripting.filesystemobject")
 Set fld = FSO.GetFolder(vSourceDir)
 Set fls = fld.Files
' Loop for each file in directroy, move from source to archive folder and record moved file to logfile
 For Each f In fls
  If f.DateLastAccessed < DateValue(CStr(Now)) - 90 Then flog.WriteLine (f.shortname)
'  If f.DateLastAccessed < DateValue(CStr(Now)) - 30 Then f.Move vArchiveDir (Commented out)
 'Reset everything to 0 \ Blanks.
 Set FSO = Nothing
 Set f = Nothing
 Set fld = Nothing
 Set fls = Nothing
 Set vSourceDir = Nothing
 Set vArchiveDir = Nothing
Question by:dutboy
    1 Comment
    LVL 85

    Accepted Solution

    Here's my take on it...

    Dim fso, OlderThanDate, logFileName, logFile, startFolder

    OlderThanDate = DateAdd("d", -90, Date)
    startFolder = "C:\Documents and Settings\Michael\My Documents\1 VB Code\2 VBScript Testing"
    logFileName = "c:\" & CStr(Replace(FormatDateTime(Now, vbShortDate), "/", "-", 1, -1, 1)) & ".txt"

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set logFile = fso.CreateTextFile(logFileName, True)

    logFile.WriteLine "Recursive Search Starting In: " & startFolder
    logFile.WriteLine "For Files Older Than: " & OlderThanDate
    logFile.WriteLine "------------------------------"

    SearchForFiles startFolder, OlderThanDate, logFile

    Function SearchForFiles(folderName, BeforeDate, logFileStream)
        Dim folder, file, fileCollection, folderCollection, subFolder

        Set folder = fso.GetFolder(folderName)
        Set fileCollection = folder.Files
        For Each file In fileCollection
            If file.DateLastModified < BeforeDate Then
                logFileStream.WriteLine file.Path
                logFileStream.WriteLine file.DateLastModified
                logFileStream.WriteLine "------------------------------"
            End If

        Set folderCollection = folder.SubFolders
        For Each subFolder In folderCollection
           SearchForFiles subFolder.Path, BeforeDate, logFileStream
    End Function

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Suggested Solutions

    INTRODUCTION We all know how to code. But at times you simply want to insert a common code block into your existing code and amend it as per your requirements. This tool not only saves you time but also saves you the pain of typing it all out aga…
    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    779 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

    11 Experts available now in Live!

    Get 1:1 Help Now