Submitted By: Anonymous Submission

Deletes the oldest subfolder in a folder. Must be run from within the parent folder.

Visual Basic
Edit|Remove
'Delete the Oldest Subfolder
   Set objFSO = CreateObject("Scripting.FileSystemObject")
   Set objFolder = objFSO.GetFolder("C:\Backups")
   Set colSubfolders = objFolder.Subfolders
   For Each objSubfolder in colSubfolders
     If Not IsObject(objOldest) Then
       ' Save first subfolder
       Set objOldest = objSubfolder
     Else
       ' Save older subfolder
       If objSubfolder.DateCreated < objOldest.DateCreated Then
         Set objOldest = objSubfolder
       End If
     End If
   Next

Wscript.Echo "SubFolder Name: " & objOldest.Name & _
                ", Date Created: " & objOldest.DateCreated & _
			" deleted"

objFSO.DeleteFolder(objOldest.Name)