for /F %%i in ('dir /b "C:\Program Files\Apache folder\*.*"') do (
echo Folder is NON empty
goto launch_app
)
如何检查文件夹是否为空?
我尝试了上面的命令,但是没有用。
for /F %%i in ('dir /b "C:\Program Files\Apache folder\*.*"') do (
echo Folder is NON empty
goto launch_app
)
如何检查文件夹是否为空?
我尝试了上面的命令,但是没有用。
试试这个:
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
)
文件未找到
@for /f "tokens=*" %%a in ('dir /b /a-d "C:\Progra~1\Apache"') do @...
运行此命令时看到的错误来自标准错误输出。但这只是打印到控制台的警告。当这种情况发生时,迭代的主体将不会被评估,并且基于这个“for/dir”指令的算法实际上是正确的。
现在,如果您想摆脱这个丑陋的错误消息,您需要将以下内容添加到您的脚本中,以便将标准错误重定向到空设备:
2>NUL
例如,在批处理文件中,使用适当的转义字符:
@rem Print a list of file paths
@for /f "tokens=*" %%a in ('dir /b /a-d "%srcPath%" 2^>NUL') do @echo(%srcPath%\%%a
@echo off
cls
echo.
echo.
echo.
echo TEST FOR EMPTY DIRECTORY
echo was tested with "&" without a file
echo.
echo Can use Full or Subfolder path
echo (as below) of where test.bat
echo.
set p=Raw\
echo.
echo Just to show p is set
echo.
echo "p=%p%"
echo.
echo.
echo.
pause
for /F %%i in ('dir /b /a "%p%*"') do (
echo Folder %p% was NOT empty
goto :process
)
echo Folder %p% was empty
:process
echo "BLAH, BLAH, BLAH "
:end
pause
exit
rem Copy past in notepad to try. "Create and use or change the "raw" to your own fancy."
rem Hope this helps. Works great for me and I use it.
rem Have Fun.
rem Note use go to end next line after was empty. Worked great in w10. (this program hmm)
rem IF IT WORKS FOR YOU . GIVE A +. THX!
dir C:\TEST\*.* /a/b/d/od>C:\TEMP\CHECKFOLDER
for /R C:\TEMP\ %%? in (CHECKFOLDER) do (
if "%%~z?"=="0" (
ECHO Folder is empty.
) ELSE (
ECHO Folder is NOT empty
)
)
我对给出的答案不满意,因为我尽可能避免使用 for 循环、goto 和 temp 文件。
检查文件夹是否为空:
dir /b /s /a "C:\Program Files\Apache folder\" | findstr .>nul || (
echo Folder is empty
)
检查文件夹是否为空:
dir /b /s /a "C:\Program Files\Apache folder\" | findstr .>nul && (
echo Folder is NOT empty
)