比较批处理脚本中的两个数字 [英] Comparing two number in batch script
问题描述
如果这似乎是一个非常基本的问题,我很抱歉,但是我无法比较在批处理脚本中连续写入一个文件的两个文件大小,它不会超出 if 语句,只是卡在那里然后没有做任何事.
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:UsersAdminping.txt C:UsersAdminping.partial
set file="C:UsersAdminping.txt"
set parfile="C:UsersAdminping.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:UsersAdminstatus.log
ping -n 5 127.0.0.1 > nul
)
else
(
echo incomplete > C:UsersAdminstatus.log
ping -n 5 127.0.0.1 > nul
goto start
)
我在这里做错了什么.:(
What I'm doing wrong here. :(
问候,高拉夫
推荐答案
if cond (
...
) else (
...
)
if cond (...) else (...)
if cond (...) else command
if cond (...) else (
....
)
if cond (
....
) else command
括号的位置很重要.if
左括号需要与 if
命令在同一行.if
右括号需要与 else
子句(如果存在)在同一行.else
左括号需要与 else
子句在同一行.
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屋!