I have scripted FFExist.bat to allow a batch file to determine if a folder is empty, or contains sub-folders, or contains files, or contains both sub-folders and files.

The syntax for using FFExist.bat is:

call ffexist FolderPath Answer

where:

FolderPath is the path to the folder, like "C:\Program Files", and Answer is a call directed environment variable that will be set as follows:

<b>XX</b> - The <b>FolderPath</b> does <b>NOT</b> exist.
<b>NN</b> - The <b>FolderPath</b> is empty.
<b>YN</b> - The <b>FolderPath</b> contains sub-folders and does <b>NOT</b> contain files.
<b>NY</b> - The <b>FolderPath</b> contains files and does <b>NOT</b> contain sub-folders.
<b>YY</b> - The <b>FolderPath</b> contains both sub-folders and files.
NOTE: If you fail to specify the Answer argument, FFExist.bat displays Syntax: ffexist FolderPath Answer.

NOTE: If you only need to determine if the FolderPath is empty, you could use the following command line:

dir /b /a FolderPath|findstr .>nul:&&(goto :notmt)||(goto :mt)

NOTE: The above command makes use of the findstr wildcard (.) and the conditional processing symbols.

FFExist.bat contains:

@echo off
if \{%2\}==\{\} @echo Syntax: ffexist FolderPath Answer&goto :EOF
setlocal
if not exist %1 endlocal&set %2=XX&goto :EOF
dir %1 /a|findstr /c:" 0 File">NUL:&&(set file=N)||(set file=Y)
dir %1 /a|findstr /c:" 2 Dir">NUL:&&(set fold=N)||(set fold=Y)
endlocal&set %2=%fold%%file%