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.
Asked
Active
Viewed 61 times
-1
-
1Why 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 Answers
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