在批处理脚本比较两个数 [英] Comparing two number in batch script
问题描述
我很抱歉,如果它似乎是一个非常基本的问题,但我不能比较,其中一个文件被批处理脚本连续写了两篇文件大小,它没有超越if语句,只是卡住那里出来,而不做任何事情。
:START
复制C:\\用户\\管理\\ ping.txt C:\\用户\\管理\\ ping.partial
设置文件=C:\\用户\\管理\\ ping.txt
集PARFILE =C:\\用户\\管理\\ ping.partial
平-n 5 127.0.0.1> NUL
FOR %% A IN(%文件%)DO设置大小= %%〜ZA
FOR %% B IN(%PARFILE%)DO设置parsize = %%〜ZB型
回声%大小%
回声%parsize%
如果大小%EQU%%parsize%
(
ECHO文件是完整的和GT; C:\\用户\\管理\\ status.log
平-n 5 127.0.0.1> NUL
)
其他
(
不完全呼应GT&; C:\\用户\\管理\\ status.log
平-n 5 127.0.0.1> NUL
转到启动
)
我做错了这里。 (
问候,
拉夫
如果COND(
...
)其他(
...
)如果COND(...)否则(...)
如果COND(...)其他指令
如果COND(...)其他(
....
)
如果COND(
....
)其他命令
括号事项的位置。在如果
开括号必须在同一行的如果
命令。在如果
右括号必须在同一行的其他
子句(如果present)。在其他
开括号必须在同一行的其他
子句。
I'm sorry if it seems a very basic question, but I cant compare two file sizes where one file is being written continuously in batch script, it doesn't go beyond if statement, just get stuck there and comes out without doing anything.
:START
copy C:\Users\Admin\ping.txt C:\Users\Admin\ping.partial
set file="C:\Users\Admin\ping.txt"
set parfile="C:\Users\Admin\ping.partial"
ping -n 5 127.0.0.1 > nul
FOR %%A IN (%file%) DO set size=%%~zA
FOR %%B IN (%parfile%) DO set parsize=%%~zB
echo %size%
echo %parsize%
if %size% EQU %parsize%
(
ECHO file is complete > C:\Users\Admin\status.log
ping -n 5 127.0.0.1 > nul
)
else
(
echo incomplete > C:\Users\Admin\status.log
ping -n 5 127.0.0.1 > nul
goto start
)
What I'm doing wrong here. :(
Regards, Gaurav
if cond (
...
) else (
...
)
if cond (...) else (...)
if cond (...) else command
if cond (...) else (
....
)
if cond (
....
) else command
The placement of the parenthesis matters. The if
opening parenthesis needs to be on the same line that the if
command. The if
closing parenthesis needs to be in the same line that the else
clause (if present). The else
opening parenthesis needs to be in the same line that the else
clause.
这篇关于在批处理脚本比较两个数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!