Find Newest SubFolder in a Folder

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Find Newest SubFolder in a Folder

Post by Marcus Tettmar » Tue May 16, 2006 12:06 pm

This is a variation of this script to find the latest subfolder:

VBSTART
Function NewestSubFolder(Folder)
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(Folder)
dPrevDate = "0"
For Each oSubFolder In oFolder.SubFolders
If DateDiff("s", dPrevDate, oSubFolder.DateLastModified) > 0 Then
sNewestSub = oSubFolder.Path
dPrevDate = oSubFolder.DateLastModified
End If
Next
NewestSubFolder = sNewestSub
End Function
VBEND
VBEval>NewestSubFolder("c:\temp"),folderpath
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts