-1

i want to write a batch script where i need to check if a directory is empty or not, if not empty i want to clean that particular directory. Path will passed via command line argument.

Mayank Srivastava
  • 149
  • 1
  • 3
  • 18
  • 1
    Why bother checking if the folder is empty first? Simply delete all files/folders each time. If the folder is already empty or does not exist, then the delete operation will be just as fast as checking if it is empty. – dbenham Oct 21 '17 at 15:11

1 Answers1

0

Here's some example code to get you started:

@Echo Off
If "%~1"=="" GoTo :EOF
If Not Exist "%~1\" GoTo :EOF
Dir/B/A "%~1\*"|Find /V "">Nul&&Call :CleanIt
Pause
GoTo :EOF

:CleanIt
Rem Your clean command(s) here

You should only need to add your specific code to the bottom

Compo
  • 36,585
  • 5
  • 27
  • 39