Option Explicit
'######################
'# SETUP DEFAULTS #
'######################
Main
Sub Main
Dim Path
Dim fso
Dim folder
Dim item
Dim highepoch
Dim highepochname
Dim curepoch
Select Case WScript.Arguments.Count
Case 1: Path = WScript.Arguments(0)
Case Else: WScript.Echo "Invalid number of arguments.": Exit Sub
End Select
Set fso = CreateObject("Scripting.FileSystemObject")
set folder = fso.GetFolder(Path) 'create the folder object for the base folder
highepoch = 0
For Each item in folder.SubFolders 'loop through all folders under specified path
curepoch = DateDiff("s", "01/01/1970 00:00:00", item.DateCreated) 'find the epochtime for the folder
If curepoch > highepoch Then 'if its the highest epochtime so far it means its newer than all others so far
highepoch = curepoch
highepochname = item.Path
End If
Next
For Each item in folder.SubFolders 'loop folders again this time we know the highest folder time
If item.Path <> highepochname Then 'if this isnt the highest folder time them we delete it
fso.DeleteFolder(item.Path)
End If
Next
set folder = Nothing
set fso = Nothing
End Sub