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.开发者_如何学JAVA
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!
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
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
精彩评论