# Batch: Check if folder



## Duddle (Sep 10, 2005)

Hi!

Currently I have to write a batch file, where at some point I need to check if a folder is empty. But I haven't found a solution to this yet, search engines only gave tips about rmdir (that only deletes empty folders).

Is it possible with a batch command? Or is there some neat workaround for this?


Thanks in advance!

Duddle


----------



## gurutech (Apr 23, 2004)

try:

rd (foldername)
if errorlevel 1 goto NOTEMPTY
if errorlevel 0 goto EMPTY
goto END

when rd (or rmdir) exists with an errorlevel of 1 (or anything higher), meaning it could not remove the directory, you will know there are files there. if rd exits with an errorlevel of 0 (meaning there were no errors), then you know the directory was empty, and is now deleted.


----------

