Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8165045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:26:55+00:00 2026-06-06T19:26:55+00:00

So I have been trying to figure this out for a while, but nothing

  • 0

So I have been trying to figure this out for a while, but nothing came to me. I have narrowed it down to a small case, so please let me know your thoughts.

I have a directory of files (1-a.txt and 1-b.txt) and a batch file like this:

for %%X in (1) do ^
fc %%X-a.txt %%X-b.txt > tmp.txt &^
if errorlevel 0 (echo 5) else (echo 6) &^
echo 7

Basically, I want it to echo 5 if the files are the same and 6, 7 if they are different.
However, it ALWAYS echos 5. Echo 7 is ignored entirely.

Any thoughts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T19:26:56+00:00Added an answer on June 6, 2026 at 7:26 pm

    if errorlevel is true when the error level is at least 0. It’s always a greater than or equal comparison:

    C:\>help if
    Performs conditional processing in batch programs.
    
    ...
    
      ERRORLEVEL number Specifies a true condition if the last program run
                        returned an exit code equal to or greater than the number
                        specified.
    

    Usually you can just switch the branches around:

    if errorlevel 1 (echo 6) else (echo 5)
    

    In your case I’d also advise you to use parentheses to group statements:

    for %%X in (1) do (
      fc %%X-a.txt %%X-b.txt > tmp.txt
      if errorlevel 1 (echo 6) else (echo 5)
      echo 7
    )
    

    As another option to the explicit if after the program call there are also operators that run another command depending on the outcome of the previous one:

    fc %%X-a.txt %%X-b.txt > tmp.txt && echo 5 || echo 6
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to figure this out for quite a while, but what
I have been pulling my hair trying to figure this out but nothing is
I have been trying to figure this out for a while now, but every
I have been trying for a while now, but I can't figure out how
Okay I've been trying to figure this out for a while now. I have
I have been trying to figure this problem out without asking for help, but
I've been trying to figure this out for a while, but what is the
This is something that I have been trying to figure out for a while
I have been trying to figure this out for a while now and decided
I have been trying to figure this out for way to long tonight. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.