Check folder is empty using batch command?

ε祈祈猫儿з 提交于 2019-12-10 05:30:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!