I have a directory C:\Test\Test2\Test3\Test4
I need to programmatically delete it but only if Neither folder contains any files.
Foe example if there is one file test.txt in Test2, besides folder Test3, then I want only Teast4 and Test3 folders deleteed and I want C:\Test\Test2\test.txt left intact. But if neither directory contains any files, i want them all deleted. Is there a way to traverse through directories, checking for files and delting empty directories?
Dim objFSO, strFolder, strFile
set objFSO = createobject("Scripting.FileSystemObject")
IF objFSO.FolderExists(strFolder) Then
If ((objFSO.GetFolder(strFolder).SubFolders.Count = 0) AND (objFSO.GetFolder(strFolder).Files.Count = 0)) Then
objFSO.DeleteFolder strFolder, true
and passed it C:\Test\Test2\Test3\Test4 as an argument
and it only removes Test4 folder, leaving C:\Test\Test2\Test3\ even though there are not any files