Script Help to sync to multiple folders

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cthomas
    Enthusiast
    • Dec 2008
    • 28

    Script Help to sync to multiple folders

    Since I have the same question Christoph told me to post in this thread. I'm trying to create my script on the example here http://www.scootersoftware.com/vbull...ead.php?t=4248. As you can see in my script I don't have it right but I don't know how to change. One other thing I want to add to the script is to do a Binary comparison. Would some body take a look at the attached script and tell me how to fix it?
  • Aaron
    Team Scooter
    • Oct 2007
    • 16000

    #2
    Hello,

    It seems like you have a couple of different scripts all in one.

    First and foremost: load bcompare.exe @scriptFile.txt "folder1" "folder2" does not belong in our script files. That would be in the bat file, and would not have a "load" in the front. I recommend reading the example scripts in the Help file under Using Beyond Compare -> Sample Scripts. Start with a script that only works on one folder pair. Once that is working, expanding it will be easier.

    I also strongly recommend using this on test data or backed up data. The Mirror command can delete information, so you want to be comfortable with how it works before you use it.

    your basic script may be:
    log normal "C:\My Documents\Webpage\Synclog.txt"
    criteria binary
    load "D:\Images Test" "ftp://[email protected]/webroot/NEWTESTFOLDER"
    sync update:lt->rt


    This would then be called from the command line:
    c:\program files\beyond compare 3\bcompare @c:\location\bcscript.txt

    You can email us your exact script at [email protected] and we can help tell you how to change it. Please include a link to this forum post so we can quickly catch up in the email.
    Aaron P Scooter Software

    Comment

    • cthomas
      Enthusiast
      • Dec 2008
      • 28

      #3
      Originally posted by Aaron
      Hello,

      It seems like you have a couple of different scripts all in one.

      First and foremost: load bcompare.exe @scriptFile.txt "folder1" "folder2" does not belong in our script files. That would be in the bat file, and would not have a "load" in the front. I recommend reading the example scripts in the Help file under Using Beyond Compare -> Sample Scripts. Start with a script that only works on one folder pair. Once that is working, expanding it will be easier.

      I also strongly recommend using this on test data or backed up data. The Mirror command can delete information, so you want to be comfortable with how it works before you use it.

      your basic script may be:
      log normal "C:\My Documents\Webpage\Synclog.txt"
      criteria binary
      load "D:\Images Test" "ftp://[email protected]/webroot/NEWTESTFOLDER"
      sync update:lt->rt


      This would then be called from the command line:
      c:\program files\beyond compare 3\bcompare @c:\location\bcscript.txt

      You can email us your exact script at [email protected] and we can help tell you how to change it. Please include a link to this forum post so we can quickly catch up in the email.
      I sent my script as an attachment. When you get a chance would you take a look at it and let me know the changes I need to make so it will work? Also where should I place the script? This is my first attempted at scripting.

      Comment

      • Aaron
        Team Scooter
        • Oct 2007
        • 16000

        #4
        I replied to your script email on 12/10 @ roughly 3:10pm. The email was sent from [email protected] and has a script attached. If you have trouble finding it, check your junk mail and/or add [email protected] to your 'Allowed' email list and we can then resend it.

        Your script file can go "anywhere", but the command line has to call to that location.
        If you would open your command prompt and type: "c:\program files\beyond comapre 3\bcompare.exe" to launch the program, then the script call would be
        "c:\program files\beyond comapre 3\bcompare.exe @c:\folderwherescriptis\testScript.txt"

        If you have the script file in the same folder as bcompare.exe, then you can simplify it by just calling it by name:
        "c:\program files\beyond comapre 3\bcompare.exe @testScript.txt"

        The above script in my comment is a good place to start:
        ====script.txt===
        log normal "C:\My Documents\Webpage\Synclog.txt"
        criteria binary
        load "D:\Images Test" "ftp://[email protected]/webroot/NEWTESTFOLDER"
        sync update:lt->rt
        ===========

        Are you having trouble getting that script to work?

        **Remember: Please test this on Test data until you are comfortable with how scripting works.
        Aaron P Scooter Software

        Comment

        • cthomas
          Enthusiast
          • Dec 2008
          • 28

          #5
          Originally posted by Aaron
          Your script file can go "anywhere", but the command line has to call to that location.
          If you would open your command prompt and type: "c:\program files\beyond comapre 3\bcompare.exe" to launch the program, then the script call would be
          "c:\program files\beyond comapre 3\bcompare.exe @c:\folderwherescriptis\testScript.txt"

          If you have the script file in the same folder as bcompare.exe, then you can simplify it by just calling it by name:
          "c:\program files\beyond comapre 3\bcompare.exe @testScript.txt"

          The above script in my comment is a good place to start:
          ====script.txt===
          log normal "C:\My Documents\Webpage\Synclog.txt"
          criteria binary
          load "D:\Images Test" "ftp://[email protected]/webroot/NEWTESTFOLDER"
          sync update:lt->rt
          ===========
          ====script.txt===
          log normal "C:\My Documents\Webpage\Synclog.txt"
          criteria binary
          load "D:\Images Test" "ftp://[email protected]/webroot/NEWTESTFOLDER"
          sync update:lt->rt
          ===========

          Is the above part of my script file below, or is it a script that I should run befor I run the one below? Would you put comments in the script file so I can understand what each line is doing?

          "c:\program files\beyond comapre 3\bcompare.exe @testScript.txt" This won't work for me. I'm running version 2.5.3.


          # Turn logging on
          log normal "C:\My Documents\Webpage\Synclog.txt"

          Load %1 %2
          sync update:lt->rt

          # Load the base folders
          load "D:\Images Test" "ftp://[email protected]/webroot"

          # Load the default session and exclude all but certain file types
          load bcompare.exe @scriptFile.txt "D:\Images Test" "N:\Images 1
          load bcompare.exe @scriptFile.txt "D:\Images Test" "N:\Images 2
          load bcompare.exe @scriptFile.txt "D:\Images Test" "N:\Images 3
          load bcompare.exe @scriptFile.txt "D:\Images Test" "N:\Images 4


          # Make the target identical to the source


          # Copy different files left to right, delete orphans on right
          sync mirror:left->right

          Comment

          • Chris
            Team Scooter
            • Oct 2007
            • 5538

            #6
            Here's how to sync the four folders:

            Save the following to as a text file named "c:\syncscript.txt".

            #log the script to a file
            log verbose c:\synclog.txt
            #load the first set of folders to be synced
            load "D:\Images Test" "N:\Images 1"
            #sync the loaded folders, making the right folder identical to the left
            sync mirror:left->right
            #load the second set of folders to be synced
            load "D:\Images Test" "N:\Images 2"
            #sync the loaded folders, making the right folder identical to the left
            sync mirror:left->right
            #load the third set of folders
            load "D:\Images Test" "N:\Images 3"
            #sync the loaded folders, making the right folder identical to the left
            sync mirror:left->right
            #load the fourth set of folders
            load "D:\Images Test" "N:\Images 4"
            #sync the loaded folders, making the right folder identical to the left
            sync mirror:left->right

            Once you have the script saved to a file, you can run it from the command line with the following command:
            "c:\program files\beyond compare 2\bc2.exe" @"c:\syncscript.txt"

            The quotes are needed around any path that contains spaces.

            In the script, first you load a pair of folders. Only one pair of folders can be loaded at a time. Then use the sync command to sync the folders. Load the next pair of folders, then run the sync command again.

            If you want the script to run without displaying anything on the screen, you would use the command line:
            "c:\program files\beyond compare 2\bc2.exe" /silent @"c:\syncscript.txt"
            Chris K Scooter Software

            Comment

            • cthomas
              Enthusiast
              • Dec 2008
              • 28

              #7
              Thanks. Should I not run "criteria binary". Since I never want to have duplicate images?

              Comment

              • Aaron
                Team Scooter
                • Oct 2007
                • 16000

                #8
                Hello,

                Binary Criteria simply changes if it scans the contents of the file, or uses the default (DateTimestamp and Size) comparison. We do not do duplicate detecting, but align images side by side based on file location and file name, then determine if they are the same or different, and the copy to the other side if different.

                I would recommend performing your sync using the program's interface. Scripting is used to automate these steps, but if you only need to perform this action once, or a few times, then it is much easier to perform via the interface. You also get a preview via the interface, so you'll know which files are going to copy, and you can double click any pair to put both pictures side by side and see what they look like. In version 2, this would require the Picture Viewer plug-in, found here:
                http://www.scootersoftware.com/downl...p?zz=v2plugins

                Even if you are looking for an automated solution, I recommend performing the action interactively a few times. Script will mirror the same actions that you "click" when using the application. So by doing it a couple of times interactively, the steps that script takes will make much more sense.

                I'm also going to move this post into the BC2 forum. Let us know if you have any questions.
                Aaron P Scooter Software

                Comment

                • cthomas
                  Enthusiast
                  • Dec 2008
                  • 28

                  #9
                  Originally posted by Chris
                  Here's how to sync the four folders:

                  Save the following to as a text file named "c:\syncscript.txt".

                  #log the script to a file
                  log verbose c:\synclog.txt
                  #load the first set of folders to be synced
                  load "D:\Images Test" "N:\Images 1"
                  #sync the loaded folders, making the right folder identical to the left
                  sync mirror:left->right
                  #load the second set of folders to be synced
                  load "D:\Images Test" "N:\Images 2"
                  #sync the loaded folders, making the right folder identical to the left
                  sync mirror:left->right
                  #load the third set of folders
                  load "D:\Images Test" "N:\Images 3"
                  #sync the loaded folders, making the right folder identical to the left
                  sync mirror:left->right
                  #load the fourth set of folders
                  load "D:\Images Test" "N:\Images 4"
                  #sync the loaded folders, making the right folder identical to the left
                  sync mirror:left->right

                  Once you have the script saved to a file, you can run it from the command line with the following command:
                  "c:\program files\beyond compare 2\bc2.exe" @"c:\syncscript.txt"

                  The quotes are needed around any path that contains spaces.

                  In the script, first you load a pair of folders. Only one pair of folders can be loaded at a time. Then use the sync command to sync the folders. Load the next pair of folders, then run the sync command again.

                  If you want the script to run without displaying anything on the screen, you would use the command line:
                  "c:\program files\beyond compare 2\bc2.exe" /silent @"c:\syncscript.txt"
                  Chris with this script what happens if a new image is put in "N:\Images 4" but is not in any of the others? Or say it is in "N:\Images 4" and "N:\Images 2" but not in any of the others? I have the script scheduled to run at 1 AM every day.

                  Comment

                  • cthomas
                    Enthusiast
                    • Dec 2008
                    • 28

                    #10
                    My script works. Sort of.

                    If I put a new file in the main folder D:\Images Test. It will copy it to N:\Images 1,Images 2,Images 3, and Images 4. Which it should do. But if a new file is put in any of the other folders (which is likely to happen) it is deleted. So I need the script to update all of the folders no matter which folder has a new file or folder in it. The only time I don't want someting updated is if it matches a Binary Criteria.

                    Can this be done?

                    Comment

                    • Aaron
                      Team Scooter
                      • Oct 2007
                      • 16000

                      #11
                      To update in both directions, you need to use Timestamp. Just detecting that the files are different is not enough, since it won't know which side to replace. Sync Update uses the Newer file, and replaces the Older file.

                      I *strongly* recommend doing this interactively, so you can preview how this would work. This script will overwrite your "older" files, but it is good to double check that what you think is older is also the "Last Modified," according to Windows and Beyond Compare.

                      Let us know if you have any questions.

                      #log the script to a file
                      log verbose c:\synclog.txt
                      #load the first set of folders to be synced
                      load "D:\Images Test" "N:\Images 1"
                      sync update:all
                      #load the second set of folders to be synced
                      load "D:\Images Test" "N:\Images 2"
                      sync update:all
                      #load the third set of folders
                      load "D:\Images Test" "N:\Images 3"
                      sync update:all
                      #load the fourth set of folders
                      load "D:\Images Test" "N:\Images 4"
                      sync update:all
                      #load the first set of folders to be synced, again. Now that D:\Images has all 4's Images
                      load "D:\Images Test" "N:\Images 1"
                      sync update:all
                      #load the second set of folders to be synced, again
                      load "D:\Images Test" "N:\Images 2"
                      sync update:all
                      #load the third set of folders, again
                      load "D:\Images Test" "N:\Images 3"
                      sync update:all
                      Aaron P Scooter Software

                      Comment

                      • cthomas
                        Enthusiast
                        • Dec 2008
                        • 28

                        #12
                        Originally posted by Aaron
                        To update in both directions, you need to use Timestamp. Just detecting that the files are different is not enough, since it won't know which side to replace. Sync Update uses the Newer file, and replaces the Older file.

                        I *strongly* recommend doing this interactively, so you can preview how this would work. This script will overwrite your "older" files, but it is good to double check that what you think is older is also the "Last Modified," according to Windows and Beyond Compare.

                        Let us know if you have any questions.

                        #log the script to a file
                        log verbose c:\synclog.txt
                        #load the first set of folders to be synced
                        load "D:\Images Test" "N:\Images 1"
                        sync update:all
                        #load the second set of folders to be synced
                        load "D:\Images Test" "N:\Images 2"
                        sync update:all
                        #load the third set of folders
                        load "D:\Images Test" "N:\Images 3"
                        sync update:all
                        #load the fourth set of folders
                        load "D:\Images Test" "N:\Images 4"
                        sync update:all
                        #load the first set of folders to be synced, again. Now that D:\Images has all 4's Images
                        load "D:\Images Test" "N:\Images 1"
                        sync update:all
                        #load the second set of folders to be synced, again
                        load "D:\Images Test" "N:\Images 2"
                        sync update:all
                        #load the third set of folders, again
                        load "D:\Images Test" "N:\Images 3"
                        sync update:all
                        Let me see if I understand this. I run the script the first time so all the folders have the same images. The next day a new image is put one of the N:\Images folder. It does not matter which one. Now I run this script again and the new image will be put in all of the folders that does not have the new image. Is this right?

                        "I *strongly* recommend doing this interactively, so you can preview how this would work." What do you mean interactively?

                        " "Last Modified," according to Windows and Beyond Compare." Is this because Windows and Beyond Compare uses different critera?

                        Comment

                        • Michael Bulgrien
                          Carpal Tunnel
                          • Oct 2007
                          • 1772

                          #13
                          Yes, Aaron's script syncs all N:\ folders with the D:\ folder so that the D:\ folder gets the file no matter what N:\ folder it was in.

                          When the final folder (N:\Images 4) is sync'd with the D:\ folder, it will have accumulated any new files that were in the previous three N:\ folders.

                          Aaron's script then re-syncs the D:\ folder back to the first three D:\ folders so that they will get all of the images that sync'd to the D:\ folder from the other N:\ folders.
                          BC v4.0.7 build 19761
                          ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

                          Comment

                          • Michael Bulgrien
                            Carpal Tunnel
                            • Oct 2007
                            • 1772

                            #14
                            Originally posted by cthomas
                            "I *strongly* recommend doing this interactively, so you can preview how this would work." What do you mean interactively?
                            "Interactively" usually means performing the script step by step and observing the changes in each folder, between each step. In other words, before using any merge script against data you don't want to lose, it is always a wise choice to test the script and know that it is doing precisely what you expect it to be doing. That way there are no suprises (data loss) when you run the process against files you care about.

                            Originally posted by cthomas
                            " "Last Modified," according to Windows and Beyond Compare." Is this because Windows and Beyond Compare uses different critera?
                            Beyond Compare uses the same "Last Modified" date as Windows. Windows also keeps track of "Created" and "Last Accessed" dates. BC3 does not use the Created and Last Accessed dates.

                            If you copy an old file, for example, and windows changes the "Created" and "Last Modified" date, the file may appear to be newer than another file that was actually modified after the older file you just copied. Understanding how Windows updates the date/time stamps during the execution of your script is important so that you know what BC3 will do with your files after a copy triggers Windows to update the date/time stamp.

                            Aaron provided a script and is simply suggesting that you test it thoroughly to ensure that it does exactly what you want it to. It might need to be tweaked further if your testing reveals a scenario where something unexpected happens.
                            BC v4.0.7 build 19761
                            ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

                            Comment

                            • Aaron
                              Team Scooter
                              • Oct 2007
                              • 16000

                              #15
                              Thanks for the detailed explination on timestamps, Michael. One quick note: cthomas is actually using BC2.

                              I do think the script should be tested step by step, but by interactively, I actually meant using the program's GUI, and manually loading folders, clicking buttons, etc. I understand that a script solution is needed in the end, but script is merely a way of automating steps taken in the program. Each line of script corresponds to a button or setting in the program's interface. By using the interface, the script itself will make much more sense. Also, the interface will provide dialog pop-ups that show previews, etc, so you can see what is about to happen before it does.

                              With script, the script will perform all the actions, and you can only analyze the final output. Using the program interactively (launching BC2.exe and using a Directory Viewer on test data), you can look at the script steps we've provided and take each action of each line manually. Or just play around with the program a bit. By being more familiar with the interface, the script will make more sense.

                              Let us know if you have any questions.
                              Aaron P Scooter Software

                              Comment

                              Working...