Skip to content

Instantly share code, notes, and snippets.

@Archigos
Created July 29, 2014 14:37
Show Gist options
  • Save Archigos/66826a49293b316b2b9b to your computer and use it in GitHub Desktop.
Save Archigos/66826a49293b316b2b9b to your computer and use it in GitHub Desktop.
Remove Empty Directories Except Number of Passes as Variable Ex: "removeempty 4"
@ECHO OFF
SET Executed=0
SET Run=1
IF "%~1" == "" (
SET ExecuteTotal=1
) ELSE (
SET ExecuteTotal=%~1
)
:Loop
ECHO Making %Run% of %ExecuteTotal% Passes
for /f "delims=" %%d in ('dir /s /b /ad ^| sort /R') do rd "%%d"
SET /A Executed=%Executed%+1
SET /A Run=%Executed%+1
IF %Executed% == %ExecuteTotal% GOTO Done
GOTO Loop
:Done
CLS
ECHO Complete
EXIT /B
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment