Check folder empty using command line?

for /F %%i in ('dir /b "C:\Program Files\Apache folder\*.*"') do ( echo Folder is NON empty goto launch_app ) 
  • How to check if a folder is empty?

    I tried to execute the command, but that did not work.

+4
source share
2 answers

try the following:

 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 ) 
+10
source

File not found

 @for /f "tokens=*" %%a in ('dir /b /ad "C:\Progra~1\Apache"') do @... 

The error that you see when you run this command appears for standard error output. But this is only a warning printed on the console. When this happens, the iteration body will not be evaluated, and the algorithm based on this "for / dir" instruction is actually right.

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 a null device:

 2>NUL 

so, for example, in a batch file with the corresponding escape character:

 :: echo list of files @for /f "tokens=*" %%a in ('dir /b /ad "%srcPath%" 2^>NUL') do @echo(%srcPath%\%%a 
+1
source

Source: https://habr.com/ru/post/1492286/


All Articles