user1137370
user1137370

Reputation: 137

How to retrieve the lastly updated folder in a hierarchy of folders?

i have a directory with subfolders. These subfolders have subfolders as well. For all Folders exist a timestamp with the time when they were last modified.

For example:

Folder1(21.01.2010)
-subfolder1(22.01.2010)
-subfolder2(23.01.2010)
--subfolder1(24.01.2010)
--subfolder2(25.01.2010)
Folder2(26.01.2010)
-subfolder 1(27.01.2010)

What I need is a script that checks the latest "date modified". So the Output should be "27.01.2010".

I dont know how to start... is there a function which can list all folders??

Maybe you can help me... thank you in advance!

Upvotes: 0

Views: 857

Answers (2)

heximal
heximal

Reputation: 10517

keep the template:

  dim fs, foldercollection ,filecollection, folders, files

  Set fs=CreateObject("Scripting.FileSystemObject")
  Set fileobject = fs.GetFolder("c:\")

  Set foldercollection = fileobject.SubFolders 
  folders = ""
  files = ""
  For Each folder in foldercollection 
    folders = folders & folder.name & Chr(13)
  Next 
  Set foldercollection=nothing
  Set filecollection = fileobject.Files
  For Each file in filecollection 
    files = files & file.name & Chr(13)
  next

  MsgBox folders & files

Upvotes: 1

cusimar9
cusimar9

Reputation: 5259

To get a list of folders and modified dates

Sub GetLastModified(folderspec)
    Dim fs, f, f1, fc, s
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFolder(folderspec)
    Set fc = f.SubFolders
    For Each f1 in fc
        s = s & f1.Name 
        s = s & f1.DateLastModified
        s = s &  vbCrLf
    Next
    MsgBox s
End Sub

Then you just need to iterate to find all folders WITHIN those folders and keep a record of the latest modified date

Upvotes: 2

Related Questions