This little batch file scans the directory that was provided as a parameter and all its sub-directories for empty folders and deletes them, including the provided folder itself, if it is empty as well (or became empty after all empty sub-folders were removed).
if %Folder%==”” @echo Syntax RemoveEmptySubFolders Folder&goto :EOF
if not exist %Folder% @echo Syntax RemoveEmptySubFolders Folder – %Folder% not found.&goto :EOF
REM REMOVE EMPTY SUBFOLDERS
for /f “tokens=*” %%A in (‘dir /ad /s /b %Folder% ^|Sort /Reverse’) do (
rmDir “%%A” 2>NUL
REM REMOVE FOLDER, IF EMPTY
rmDir %Folder% 2>NUL