Amit
Amit

Reputation: 11

How to find last modified subfolder?

I have a log folder that contains subfolders with log files of a build server. Each time a build is triggered, a new subfolder is created with log files. I want to find the path to the last created subfolder within the main build folder.

Can anyone point me in the right direction?

Upvotes: 1

Views: 9705

Answers (1)

Fionnuala
Fionnuala

Reputation: 91316

You can use the FileSystemObject.

Set fs = CreateObject("Scripting.FileSystemObject")
Set MainFolder = fs.GetFolder("C:\Docs")
For Each fldr In MainFolder.SubFolders
    ''As per comment
    If fldr.DateLastModified > LastDate Or IsEmpty(LastDate) Then
        LastFolder = fldr.Name
        LastDate = fldr.DateLastModified
    End If
Next

MsgBox LastFolder

Upvotes: 3

Related Questions