Announcement

Collapse
No announcement yet.

Copying file by script

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

  • Copying file by script

    I'm still working on a FTP backup Applescript by sending
    Code:
    bcompare@ "my_script.txt"
    It works fine to SYNC mirror folders but I would like to know if it's possible copy only files.

    I don't understand how to use command like COPYTO
    Code:
    copyto [left|right|all] [path:(relative|base|none)] <path>
    with only one path (source or destination), as I need both source and destination path.

    Thank you for your help.

  • #2
    Hello,

    The one path is the target (The "to" it will copy to). The immediately previous line should be a "select" line, and before that an "expand all".

    For example, something like this:
    load "c:\folder1" "c:\folder2"
    expand all
    select all.newer.files all.orphan.files
    copyto all path:base "c:\destination"

    I would recommend stepping through this in the graphical interface (load the Folder Compare, expand, use the display filters to limit the view, Expand All command, Select All Files command, right click and Copy To Folder command on the selection.
    Aaron P Scooter Software

    Comment


    • #3
      Thank you Aaron for you quick and detailed answer.
      If I well understand (my english is not very good), this will not fill my personal need. I was trying to copy a single local file to a distant folder without graphical UI.
      The goal was to drop a single file onto an Applescript droplet to copy it to my FTP folder, regardless it already exists in the destination folder, but I don't think it's possible.

      So it would be something like :
      Code:
      load "path_to_my_file" "my_distant_ftp_folder
      or
      Code:
      copy "path_to_my_file" "my_distant_ftp_folder
      Originally posted by Aaron View Post
      For example, something like this:
      load "c:\folder1" "c:\folder2"
      expand all
      select all.newer.files all.orphan.files
      copyto all path:base "c:\destination"

      Comment


      • #4
        Hello,

        For a specific file, you could set a filter to only that file's location. I would also recommend setting this in the graphical interface first:
        load your two folders
        set a file name filter to only the file you want to copy, and note the syntax used in the Filter toolbar: ".\folderto\filename.txt"

        In script, you can copy and paste the filter, adding quotes:
        filter ".\folderto\filename.txt"
        load "c:\folder1" "c:\folder2"
        expand all
        select all.files
        copyto all path:base "c:\destination"

        Once the script is working for a very specific file, you can broaden it with variables:
        bcompare.exe "@c:\bcscript.txt" "c:\folder1" "c:\folder2" ".\folderto\filename.txt" "c:\destinationfolder"

        where bcscript.txt is:
        filter "%3"
        load "%1" "%2"
        expand all
        select all.files
        copyto all path:base "%4"

        Please always intially test script against test files and folder locations. BC4 does not support UNDO, and does not preview before taking script actions.
        Aaron P Scooter Software

        Comment


        • #5
          Great!

          It works fine
          Thank you very much for your help, Aaron.

          I only have just little problem with option confirm:yes-to-all
          I added option confirm:yes-to-all as the last line of my text file (the one called by bcompare @) but I always have replacement confirmation dialogs when file already exists in the distant destination folder.

          Comment


          • #6
            option confirm:yes-to-all should be one of the first lines in your script. BC reads and runs each line as it comes to it, so if it's last it won't have any effect since everything is already done.
            Zoë P Scooter Software

            Comment


            • #7
              Ok, it works
              Thank you very much.

              Comment


              • #8
                I need your help once again for copyto scripting options.

                I would like to copy a folder from a local folder named localFolder/ to a distant sftp folder named TestFolder/. I don't want a mirror, just a very basic copy where the content of an existing folder is replaced by the new content.

                For example:

                A local folder named testCopy contains 3 documents:
                mydoc_01.txt
                mydoc_02.txt
                mydoc_03.txt


                During the first copyto script, testCopy folder is copied to the sftp server.
                This is the log:
                24/10/2018 10:24:51 >> log verbose "/Users/thierry/Desktop/BCompare Backups log.txt"
                24/10/2018 10:24:51 >> filter "testCopy/;-.DS_Store"
                24/10/2018 10:24:51 >> load create:right "/Volumes/localFolder/" "sftp://***"
                24/10/2018 10:24:51 Charger la comparaison : /Volumes/localFolder <-> sftp://***/TestFolder
                24/10/2018 10:24:51 >> select all.folders
                24/10/2018 10:24:51 >> option confirm:yes-to-all
                24/10/2018 10:24:51 >> copyto all path:base "sftp://***"
                24/10/2018 10:24:51 /Volumes/localFolder/testCopy/mydoc_01.txt copié vers sftp://***/TestFolder/testCopy
                24/10/2018 10:24:51 /Volumes/localFolder/testCopy/mydoc_02.txt copié vers sftp://***/TestFolder/testCopy
                24/10/2018 10:24:51 /Volumes/localFolder/testCopy/mydoc_03.txt copié vers sftp://***/TestFolder/testCopy
                24/10/2018 10:24:52 La copie de 3 éléments a réussi. Terminé en 0,11 secondes.
                24/10/2018 10:24:52 >>
                24/10/2018 10:24:52 Script terminé en 0,86 secondes
                Now, I deleted mydoc_01.txt from my local folder, and launch again my copyto script.
                This is the new log:
                24/10/2018 10:26:08 >> log verbose "/Users/thierry/Desktop/BCompare Backups log.txt"
                24/10/2018 10:26:08 >> filter "testCopy/;-.DS_Store"
                24/10/2018 10:26:08 >> load create:right "/Volumes/localFolder/" "sftp://***"
                24/10/2018 10:26:08 Charger la comparaison : /Volumes/localFolder <-> sftp://***/TestFolder
                24/10/2018 10:26:08 >> select all.folders
                24/10/2018 10:26:08 >> option confirm:yes-to-all
                24/10/2018 10:26:08 >> copyto all path:base "sftp://***"
                24/10/2018 10:26:08 /Volumes/localFolder/testCopy/mydoc_02.txt copié vers sftp://***/TestFolder/testCopy
                24/10/2018 10:26:08 /Volumes/localFolder/testCopy/mydoc_03.txt copié vers sftp://***/TestFolder/testCopy
                24/10/2018 10:26:08 sftp://***/TestFolder/testCopy/mydoc_01.txt copié vers sftp://***/TestFolder/testCopy
                24/10/2018 10:26:08 sftp://***/TestFolder/testCopy/mydoc_02.txt copié vers sftp://***/TestFolder/testCopy
                24/10/2018 10:26:08 sftp://***/TestFolder/testCopy/mydoc_03.txt copié vers sftp://***/TestFolder/testCopy
                24/10/2018 10:26:08 La copie de 5 éléments a réussi. Terminé en 0,15 secondes.
                I would like the distant folder to be exactly the same as the local one, with mydoc_01.txt deleted.
                Furthermore, I don't understand why 5 items have been copied.

                I guess I don't use the right options.
                Thank you.

                Comment


                • #9
                  Hello,

                  It looks like you have 5 items copied because you have 5 total folders on both sides.
                  select all.folders would select all folders on both sides. You would have to add a side parameter to only select an origin side (left.all.folders).

                  BC4 does not have a method to automatically propagate deletes to a 3rd location. You would have to load the target location as a base folder and use a combination of the select command and delete commands to carefully delete the needed files.
                  However, if your two folders were side by side, you could perform a Sync Mirror to sync from Left to Right, which deletes anything on the right that does not exist on the left.
                  ***Please note that BC4 does not support UNDO.***
                  It is strongly recommended to test any sync, especially Mirror, with Test or Temp locations first to see how it interacts since the action cannot be undone. Also, script offers no preview before committing the action. This could result in an unpreviewed action deleting files depending on the current configuration, with no method to restore or undo.
                  Aaron P Scooter Software

                  Comment


                  • #10
                    left.folders is the solution for my need, thank you.

                    Concerning a folder's content, unfortunately, both folders are not always side by side. I understand I would have to use wisely the delete command.

                    Comment

                    Working...
                    X