问题
for /F %%i in ('dir /b "C:\Program Files\Apache folder\*.*"') do (
echo Folder is NON empty
goto launch_app
)
How to check a folder is empty?
I tried above command, but it didn't work.
回答1:
try this:
for /F %%i in ('dir /b /a "C:\Program Files\Apache folder\*"') do (
echo if you see this the folder is NOT empty
goto launch_app
)
回答2:
File Not Found
@for /f "tokens=*" %%a in ('dir /b /a-d "C:\Progra~1\Apache"') do @...
The error that you see when you run this command, comes for the standard error output. But that is only a warning printed to your console. When this case happens, the body of the iteration won't be evaluated, and the algorithm based on this "for/dir" instruction, is in fact correct.
Now, if you want to get rid of this ugly error message, you need to add the following to your script, in order to redirect the standard error to null device:
2>NUL
so for instance, in a batch file, with the appropriate escape character:
:: echo list of files
@for /f "tokens=*" %%a in ('dir /b /a-d "%srcPath%" 2^>NUL') do @echo(%srcPath%\%%a
来源:https://stackoverflow.com/questions/17744981/check-folder-is-empty-using-batch-command