Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I modify this existing script? 1

Status
Not open for further replies.

ccoyle

MIS
Jan 30, 2003
17
US
Hi All,
Below is a script I've been working with for some time - works very well. I need to modify it and am not sure how. Currently this will give me last modified of all files in all subdirectories. Simply enter the directory, enter where I want the output .txt to go and enter how many days back I want it to start listing. I need to add DateLastAccessed so the .txt lists full directory path\file, size, last modified and last accessed. I think it would make sense to keep the last modified logic the same so I can populate the .txt by that criteria and then add the DateLastAccessed to anything that "hits the radar".

Thanks for any assistance!
-Chris

Script>

Option Explicit

Dim oFSO, oFolder, sDirectoryPath, sStartPath, oFSO1, sReportName, fReport, oFldr
Dim oFileCollection, oFile, sDir
Dim iDaysOld

sStartPath = "H:\DIRECTORY"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFSO1 = CreateObject("Scripting.FileSystemObject")
sReportName = "C:\temp\DIRECTORY.txt"
Set fReport = oFSo1.CreateTextFile(sReportName, True)
fReport.WriteLine "File Path" & vbTab & "File Size" & vbTab & "Last Modified Date"
ListFolders(sStartPath)
Sub ListFolders(sDirectoryPath)
On Error Resume Next
iDaysOld = 731

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(sDirectoryPath)
Set oFileCollection = oFolder.Files

For each oFile in oFileCollection


If oFile.DateLastModified < (Date() - iDaysOld) Then

fReport.write oFile & vbtab
fReport.write oFile.Size & vbtab
fReport.Write oFile.DateLastModified & vbnewline
End If

Next
For Each oFldr In oFolder.SubFolders
ListFolders oFldr.Path
Next
End Sub

Set oFSO = Nothing
Set oFolder = Nothing
Set oFileCollection = Nothing
Set oFile = Nothing
 
What about this ?
Code:
Option Explicit
Dim oFSO, sStartPath, sReportName, fReport
sStartPath = "H:\DIRECTORY"
Set oFSO = CreateObject("Scripting.FileSystemObject")
sReportName = "C:\temp\DIRECTORY.txt"
Set fReport = oFSO.CreateTextFile(sReportName, True)
fReport.WriteLine "File Path" & vbTab & "File Size" & vbTab & "Last Modified Date" & vbTab & "DateLastAccessed"
ListFolders sStartPath
Set oFSO = Nothing

Sub ListFolders(sDirectoryPath)
Dim iDaysOld, oFolder, oFile, oFldr
iDaysOld = 731
Set oFolder = oFSO.GetFolder(sDirectoryPath)
For Each oFile In oFolder.Files
  If oFile.DateLastModified < (Date - iDaysOld) Then
    fReport.Write oFile & vbTab
    fReport.Write oFile.Size & vbTab
    fReport.Write oFile.DateLastModified & vbTab
    fReport.Write oFile.DateLastAccessed & vbNewLine
  End If
Next
For Each oFldr In oFolder.SubFolders
  ListFolders oFldr.Path
Next
End Sub

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
That's perfect (and much cleaner)!
Thanks a million PHV - I made you my star! :)

 
Worth pointing out that by default updating of DateLastAccessed is disabled on Vista and later (Windows 2008 / 2008 R2, Windows 7 and presumably Windows 8) for performance reasons , and will be the same as DateCreated
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top