Réj*_*ôme 8 windows file batch-file
我想检查Windows .bat文件中的特定文件是否为空.这是我的非工作脚本:
set dir="C:\test"
set file="%dir%\fff.txt"
cd %dir%
if %file%%~zi == 0 exit
ftp -s:"%dir%\ftp.action"
exit
Run Code Online (Sandbox Code Playgroud)
你能帮帮我调试吗?
或试试吧
@echo off
set "dir=C:\temp"
set "file=%dir%\a.txt"
call :CheckEmpty "%file%"
goto :eof
:CheckEmpty
if %~z1 == 0 exit
ftp -s:"%dir%\ftp.action"
goto :eof
Run Code Online (Sandbox Code Playgroud)
主要区别在于我使用函数调用并使用%~z1,因为修饰符仅适用于%1,%2 ..%9等参数或%% a等for循环参数...
使用文件比较的批处理解决方案:
type nul > blank
fc myfile blank > nul
if errorlevel 1 echo myfile is not empty
Run Code Online (Sandbox Code Playgroud)