Hi
Could someone please offer me a batch file that will delete all empty folders and subfolders in a designated place.
The reason is that I have a backup program that is set to perform incremental backups every day but in doing so it copies every folder & subfolder on the destination drive even if it's empty.
There is a setting on the program to delete the empty folders after each backup but for some reason it doesn't always work.
Any help would be appreciated.
Thanks
Assistance please with batch file to delete empty folders
Moderator: DosItHelp
Re: Assistance please with batch file to delete empty folder
This is untested but should work.
Run it inside the folder tree you want to remove the empty folders from.
Run it inside the folder tree you want to remove the empty folders from.
Code: Select all
@echo off
dir /ad /b /s |sort /r >tmp.tmp
for /f "delims=" %%a in (tmp.tmp) do rd "%%a" 2>nul
del tmp.tmp
Re: Assistance please with batch file to delete empty folder
Code: Select all
@echo off
dir /ad /b /s |sort /r >tmp.tmp
for /f "delims=" %%a in (tmp.tmp) do rd "%%a" 2>nul
del tmp.tmp
Thank you very much for your reply foxidrive, it works just fine run from the folder in question.
If I wanted to store and run this batch file from a central folder to delete empty folders on a network drive, say "F:\backup", could you tell me how to do that?
Many thanks
Re: Assistance please with batch file to delete empty folder
dobbies wrote:Code: Select all
@echo off
dir /ad /b /s |sort /r >tmp.tmp
for /f "delims=" %%a in (tmp.tmp) do rd "%%a" 2>nul
del tmp.tmp
Thank you very much for your reply foxidrive, it works just fine run from the folder in question.
If I wanted to store and run this batch file from a central folder to delete empty folders on a network drive, say "F:\backup", could you tell me how to do that?
Many thanks
dir /ad /b /s F:\backup |sort /r >tmp.tmp
Re: Assistance please with batch file to delete empty folder
Much appreciated
Thanks
Thanks