[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 286
  • Last Modified:

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

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)
  Next
 
 'Reset everything to 0 \ Blanks.
 
 Set FSO = Nothing
 Set f = Nothing
 Set fld = Nothing
 Set fls = Nothing
 Set vSourceDir = Nothing
 Set vArchiveDir = Nothing
0
dutboy
Asked:
dutboy
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
    Next

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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now