compare files and save the result to a file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bibhuti
    Journeyman
    • Aug 2016
    • 15

    compare files and save the result to a file

    Hey Aaron, Please I need your help in getting BC automized, can u please share me code how to use BC to compare files and save the result to a file programmatically ?..
  • Chris
    Team Scooter
    • Oct 2007
    • 5538

    #2
    Here's an example script to compare two files and output comparison results as HTML.

    file-report layout:side-by-side output-to:c:\report.html output-options:html-color c:\file1.txt c:\file2.txt

    To run the script, use the command line:
    "c:\program files (x86)\beyond compare 3\bcompare.exe" "@c:\script.txt"

    The @ character makes Beyond Compare run a file as a script rather than load it for interactive comparison.
    Chris K Scooter Software

    Comment

    • Bibhuti
      Journeyman
      • Aug 2016
      • 15

      #3
      I want to run this script using java so do I need to make use of Process.execute to create process for running the scripts??
      Also i want to know what are file1.txt and file2.txt, is it some BC internal scripts or files that are to be compared??
      Last edited by Bibhuti; 21-Aug-2016, 09:56 AM. Reason: I wanted to ask few more doubts

      Comment

      • Aaron
        Team Scooter
        • Oct 2007
        • 16002

        #4
        Hello,

        Scripting documentation is available in the Help file in the Using Beyond Compare -> Scripting Reference chapter.

        The core call is:
        bcompare.exe "@c:\bcscript.txt"

        Where bcscript.txt is:
        file-report layout:side-by-side output-to:c:\report.html output-options:html-color c:\file1.txt c:\file2.txt

        If you add on additional text after this call, they are parameters can be passed in as variables. This way, you can make calls from the command line without editing the script file. Like a .bat file, the variables are referenced with %1, %2, %3, etc within scripting.

        bcompare.exe "@c:\bcscript.txt" "c:\file1.txt" "c:\file2.txt"

        where this bcscript.txt is:
        file-report layout:side-by-side output-to:c:\report.html output-options:html-color "%1" "%2"
        Aaron P Scooter Software

        Comment

        • Bibhuti
          Journeyman
          • Aug 2016
          • 15

          #5
          Thanks a lot for the reply. I will try this once and will get back to you soon if encountered some errors.

          Comment

          • Bibhuti
            Journeyman
            • Aug 2016
            • 15

            #6
            Hello, Now I want to make a GUI (JSP/HTML Form) where an user will select the files to be compared, my question is how to load the selected files in the beyond compare for comparison.

            Comment

            • Aaron
              Team Scooter
              • Oct 2007
              • 16002

              #7
              Hello,

              The command line would be the same:
              bcompare "@c:\bcscript.txt" "c:\file1" "c:\file2"

              It would be up to your program to create the file name paths (file1 and file2) and pass them as text to the command line, calling bcompare.exe and @script.txt with the file paths as parameters.
              Aaron P Scooter Software

              Comment

              • Bibhuti
                Journeyman
                • Aug 2016
                • 15

                #8
                Ok thank you I will try this one

                Comment

                • Bibhuti
                  Journeyman
                  • Aug 2016
                  • 15

                  #9
                  I want to show only differences, what should be in the script??

                  Comment

                  • Aaron
                    Team Scooter
                    • Oct 2007
                    • 16002

                    #10
                    Hello,

                    Assuming a text report:

                    text-report layout:side-by-side options:display-mismatches output-to:c:\report.html output-options:html-color "c:\file1.txt" "c:\file2.txt"


                    Scripting documentation is also found in the BC4 Help file (F1) -> Using Beyond Compare, Automating with Script chapter, or in the main Scripting Reference chapter.
                    Aaron P Scooter Software

                    Comment

                    • Bibhuti
                      Journeyman
                      • Aug 2016
                      • 15

                      #11
                      May i please know the scripts to compare folder and tar files. Its kind of urgent. Thanks in advance

                      Comment

                      • Bibhuti
                        Journeyman
                        • Aug 2016
                        • 15

                        #12
                        Hey Aron, Cris Can u please tell me scripts for .tar comparison

                        Comment

                        • Aaron
                          Team Scooter
                          • Oct 2007
                          • 16002

                          #13
                          Hello,

                          Sorry, I was out sick from the office. You can load a .tar as a target folder.

                          In the graphical interface, start a new Folder Compare, and pick your two base folder targets using the Browse button or Drag and Drop from Windows Explorer. Once the paths are loaded and the comparison looks as you expect, you can copy/paste these paths out of the graphical interface and into script.txt. For example:

                          load "c:\path1\folder" "c:\path2\archive.tar"
                          expand all
                          folder-report layout:side-by-side output-to:"c:\reports\bcreport.html" output-options:html-color
                          Aaron P Scooter Software

                          Comment

                          • Bibhuti
                            Journeyman
                            • Aug 2016
                            • 15

                            #14
                            Thank You for the reply. I want to show only differences in both the .tar files. What will be the script for that??

                            Comment

                            • Bibhuti
                              Journeyman
                              • Aug 2016
                              • 15

                              #15
                              The report files shows all the files that are compared. I want to display only that file which has some differences.

                              log verbose logfile%date%.txt
                              criteria rules-based
                              load "%1" "%2"
                              expand all
                              select diff.files orphan.files
                              file-report layout:side-by-side options:ignore-unimportant,display-mismatches output-to:C:\Desktop\folderreport.html output-options:html-color


                              This script shows all the files being compared. I even tried using select all.diff it wont work.
                              Please help. Urgent help needed.
                              Last edited by Bibhuti; 27-Sep-2016, 04:11 AM. Reason: spelling mistake

                              Comment

                              Working...