Comparing two number in batch script
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.
if %size% EQU %parsize%
causes error
if opp condition opp2 command
if you modify follow this this 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