Comparing two numbers in a script package

I am very sorry if this seems like a very simple question, but I cannot compare the two file sizes, where one file is written continuously in a batch script, it does not go beyond the if statement, it just got stuck there and comes up without any action.

: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

0
source share
3 answers
 if cond ( ... ) else ( ... ) if cond (...) else (...) if cond (...) else command if cond (...) else ( .... ) if cond ( .... ) else command 

Placing questions in brackets. The opening parenthesis if must be on the same line as the if command. The closing if bracket must be on the same line as the else clause (if present). The opening parenthesis else must be on the same line as the else clause.

+5
source

if %size% EQU %parsize% causes an error

 if opp condition opp2 command 

if you change this, it will work

 IF %size% == %parsize% ECHO file is complete > C:\Users\finoy\status.log ping -n 5 127.0.0.1 > nul else echo incomplete > C:\Users\finoy\status.log ping -n 5 127.0.0.1 > nul 
+3
source

One problem is the brackets after comparing the if - it should be on the same line:

  if %size% EQU %parsize% ( 
0
source

Source: https://habr.com/ru/post/978226/


All Articles