Announcement

Collapse
No announcement yet.

QuickCompare always return 0

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • QuickCompare always return 0

    I always get 0 when running this even though the file is different:

    Code:
    @ECHO OFF
    
    SET LABEL1=%1
    SET LABEL2=%2
    SET MYDIRECTORY=%3
    
    SET BCOMPARE=C:\Program Files (x86)\Beyond Compare 3\BComp.com
    
    @setlocal enabledelayedexpansion enableextensions
    
    @for /f "delims=" %%A in ('dir /B /S %MYDIRECTORY%\*.dat')  do  (
       @setlocal enabledelayedexpansion
       "%BCOMPARE%" /qc "%%~A.%LABEL1%.PCN" "%%~A.%LABEL2%.PCN"
       @echo %errorlevel%
    )
    @pause
    @endlocal
    However, a more simplified version of this script works well:

    Code:
    @ECHO OFF
    
    SET FILE1=%1
    SET FILE2=%2
    SET BCOMPARE=C:\Program Files (x86)\Beyond Compare 3\BCompare.exe
    
    @setlocal enabledelayedexpansion enableextensions
    
    @REM "delims=" means do not parse into tokens
    
    "%BCOMPARE%" /qc=binary "%LABEL1%" "%LABEL2%"
    echo %errorlevel%
    
    @pause
    @endlocal
    Is it the for loop? Any advice?

  • #2
    Hello,

    My bat scripting is a little rusty, but %%A for the first FOR loop is including the full file path, so is the label part of a structure additional? I added an echo command into the for loop instead of calling to bcompare to make sure it was passing the correct file paths in my test case.

    For your second script, it looks like you have both FILE1 variables and LABLE1, so I'm not sure how the second script is populating the LABEL variables.
    Aaron P Scooter Software

    Comment


    • #3
      Hi Aaron,

      Sorry, I mislabeled my second script. It should be this way:

      Code:
      @ECHO OFF SET FILE1=%1 SET FILE2=%2 SET BCOMPARE=C:\Program Files (x86)\Beyond Compare 3\BCompare.exe @setlocal enabledelayedexpansion enableextensions @REM "delims=" means do not parse into tokens "%BCOMPARE%" /qc=binary "%FILE1%" "%FILE2%" echo %errorlevel% @pause @endlocal
      So here is what I am attempting to do:
      1. Go over all subdirectories under %MYDIRECTORY%
      2. Find all *.DAT (e.g. ABC.DAT) files there
      3. For each of these files, there will be two corresponding files called ABC.DAT.LABEL1.PCN and ABC.DAT.LABEL2.PCN in that same folder
      These are the two files that I want to compare.

      In the second script, I just pass in ABC.DAT.LABEL1.PCN and ABC.DAT.LABEL2.PCN into FILE1 and FILE2 variables. But I lose the ability to do a loop.

      Comment


      • #4
        Ah hah! This took a little bit to figure out, since I'm still rusty on Batch scripting, but the FOR loop itself is the issue, and you have to use !errorlevel! when within the loop to look for the Errorlevel.

        How does this work for you?
        Aaron P Scooter Software

        Comment


        • #5
          Yes! Thank you so much, Aaron!

          Comment

          Working...
          X