Yesterday I needed a Dos batch script to check if folder is empty. A little Google search revealed some methods:
- Using dir and find commands, does not work on non-english Windows versions: www.computing.net
- Using dir command with /a-d, does not work for folders: www.computing.net
- Using dir and findstr commands, does not work on non-english Windows versions: windowsitpro.com
If you want something done right do it yourself. Here is a my script:
for /F %%i in ('dir /b "c:\test directory\*.*"') do (
echo Folder is NON empty
echo Folder is empty or does not exist
Update Sep 21, 2011 – added “or does not exist”. Thanks to the Thump.
Update Jul 5, 2013 – for more code examples see the comments!