0

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

3 Answers 3

5
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.

Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

0

One issue is the parenthesis after the if compare - it must be on the same line:

 if %size% EQU %parsize% (

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.