Reputation: 31
How to get the last updated folder in a directory? Say for example I have a folder C:\test and it has many folders inside. I need the latest folder's name
Upvotes: 0
Views: 2906
Reputation: 528
this should work.
Function GetLastFolder(Path As String)
Dim FSO, FS, F, DtLast As Date, Result As String
Set FSO = CreateObject("scripting.FileSystemObject")
Set FS = FSO.GetFolder(Path).SubFolders
For Each F In FS
If F.DateLastModified > DtLast Then
DtLast = F.DateLastModified
Result = F.Name
End If
Next
GetLastFolder = Result
End Function
you can call the function like this:
GetLastFolder("c:\test")
Upvotes: 1
Reputation: 1689
One possible approach:
Use the FileDateTime(path)
function and then build a loop around it. Store the name and time from the first subfolder in respective variables and then compare the time against that variable with each pass of the loop. If it's newer, store the new name / time value, else next loop pass.
After the loop is completed your variables will hold the subfolder with the latest modification date.
Upvotes: 0