Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


recursive file traversal help needed

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,52860
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> recursive file traversal help needed
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 recursive file traversal help needed - 10/19/2007 11:30:47 AM   
  blaks

 

Posts: 1
Score: 0
Joined: 10/19/2007
Status: offline
I am trying to create a script that traverses a directory and for each folder in that directory finds the most recently modified file in that directory.  It must search for files in subdirectories to obtain the most recently used file.  The goal of this is to be able to find which of my user folders have not been accessed in a long time and then coordinate the entire folders deletion.  I do not wish to delete folders that have had recent file activity.  I would like the output to display the folder name and the most recently modified date.  I suppose someone has alerady scripted something like this but I couldnt find it.  It uses a little recursion to traverse the directory structure.  There seems to be a problem with how it scopes the latest file time.  I havent figured out variable scopes in vbscript yet.  I would like to be able to construct an object with getter and setter methods to store the vairable, but do not see any constructors in vbscript.....   Maybe one of you experts can guide me a little.  Oh, and a lot of the code was essentially snagged from other folks arround the net.  If you recognize some of the code as yours, please consider plagerism as flattery.

and thanks for tying to help :)

________________________________________________________________________________
   Dim fsoFile         'As File
   Dim topFolder       'As Folder
   Dim fso             'As FileSystemObject
   Dim dOldDate        'As Date 
   Dim currentFolder

   Set fso = CreateObject("Scripting.FileSystemObject")
   Set topFolder = fso.GetFolder("c:\I386")
  
For each SubDir in topFolder.Subfolders
rem doldDate = Nothing
showNewestDate(SubDir)
       Wscript.Echo SubDir.Name &"   "& doldDate  
       
Next

   Set fsoFile = Nothing
   Set fsoFolder = Nothing
   Set fso = Nothing



sub ShowNewestDate(Folder)

For Each Subfolder in Folder.Subfolders
 For Each fsoFile In Folder.Files                   
                If  dOldDate< fsoFile.DateLastModified Then
                     dOldDate = fsoFile.DateLastModified                            
                End If
           
 Next
 ShowNewestDate(Subfolder)
        Next
End Sub
 
 
Post #: 1
 
 RE: recursive file traversal help needed - 10/19/2007 11:56:58 AM   
  Rischip


Posts: 502
Score: 2
Joined: 3/26/2007
Status: offline
Vbscript objects have Functions, Subs, and Properties.
There aren't really any Constructors so to speak. You can't create them with parameters.

You can use the Routines below as you would constructors, but you cannot pass parameters to them.

  Private Sub Class_Initialize
     ' Statements go here.
  End Sub

  Private Sub Class_Terminate
     ' Statements go here.
  End Sub

_____________________________

Rischip
Author of - The Grim Linker

(in reply to blaks)
 
 
Post #: 2
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> recursive file traversal help needed Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts