Delete Empty Folders

email me

Check folders, delete only empty folders.

'SET PATH - ADD THE STARTING PATH HERE EX. C:\TEMP
strFolderName = "FolderPath"

'VARIABLES
Dim objFSO, objFolder
'Setting Object for FileSystem
Set objFSO = CreateObject("Scripting.FileSystemObject")

'CHECK PATH
If objFSO.FolderExists(strFolderName) Then

Set objFolder = objFSO.GetFolder(strFolderName)

'CHECK SUBFOLDERS
If objFolder.Files.Count = 0 And objFolder.SubFolders.Count = 0 Then
msgbox "Folder is Empty"
'DELETE FOLDER IF EMPTY
objFSO.DeleteFolder strFolderName
'VERIFY DELETION
If objFSO.FolderExists(strFolderName) Then
msgbox "Folder was not deleted!"
Else
msgbox "Folder was deleted!"
End If
Else
msgbox "Folder is not epty!"
End If
Else
msgbox "Folder does not exist!"
End If

'CLEAR SESSION
Set objFSO = Nothing