谷歌有几种方法可以检查文件是否为空,但我需要做相反的事情。
If (file is NOT empty)
do things
我将如何批量执行此操作?
for /f %%i in ("file.txt") do set size=%%~zi
if %size% gtr 0 echo Not empty
这应该工作:
for %%R in (test.dat) do if not %%~zR lss 1 echo not empty
help if
表示您可以NOT
直接在之后添加if
以反转比较语句
set "filter=*.txt"
for %%A in (%filter%) do if %%~zA==0 echo."%%A" is empty
键入help for
命令行以获取有关 ~zA 部分的说明
您可以利用子例程/外部批处理文件来获得有用的参数修饰符来解决这个确切的问题
@Echo OFF
(Call :notEmpty file.txt && (
Echo the file is not empty
)) || (
Echo the file is empty
)
::exit script, you can `goto :eof` if you prefer that
Exit /B
::subroutine
:notEmpty
If %~z1 EQU 0 (Exit /B 1) Else (Exit /B 0)
或者
notEmpty.bat
@Echo OFF
If %~z1 EQU 0 (Exit /B 1) Else (Exit /B 0)
yourScript.bat
Call notEmpty.bat file.txt
If %errorlevel% EQU 0 (
Echo the file is not empty
) Else (
Echo the file is empty
)