No announcement yet.

How to rename a file that was copied over

  • Filter
  • Time
  • Show
Clear All
new posts

  • How to rename a file that was copied over

    I am trying to place a file in a destination base folder and I would like to have the name of the file changed in the end. I am trying to accomplish everything with scripting but unsuccessful and looking for assistance. So I thought i could accomplish this is in two ways.
    option confirm:yes-to-all
    #Backup File to network Backup Folder
    Load create:rt "C:\Synctest" "C:\SyncTest\Backup\%username%"
    filter *_Filename.txt
    select left.newer.files left.orphan.files
    copy left->right
    filter *_Filename.txt
    select right.files
    rename "*_Filename.txt" "*_Filename_%date%.txt"

    Or the other way to maybe use copyto syntax and zip the file up with a name with a date in it. But this syntax did nothing for me...
    I tried- copyto right path:relative "C:\SyncTest\Backup\%username%\Test_Filename.z ip" in the place of rename line above and it resulted in nothing outputted.

    Also I tried to add %time% but that did not work because of the colon in the file name. Most users regional settings has this format set and I would like to know if there is another way to add time to the backup filename.

    Assistance would be greatly appreciated. Please let me know when you have a second.

  • #2

    For variables, we do not support %username%, but do have %date% and %fn_time%, documented in Help -> Using Beyond Compare -> Scripts. The rename command supports an old mask new mask format if using regular expressions, but the dos mask has just the one mask:
    rename "*_%date%.txt"
    rename regexpr (.*)\.txt $1_%date%.txt

    For scripting/rename documentation is under the Scripting Reference chapter of the Help file. If you select multiple files in the Folder Compare, then right-click Rename, this will have a similar interface and allow testing syntax if needed. Please note that BC4's interface and scripting do not offer Undo.

    The copyto command looks correct, except for the %username% variable and the ".zip" file extension containing a space character.
    Aaron P Scooter Software


    • #3
      Thanks for this information, I was always viewing the scripting reference and sample scripts, missed that information. I needed the %fn_time% variable for a file name.
      Thanks for the rename information, I was confused in the example of the regexpr example. I ended up with the dos mask.
      Not sure how a space got into my copyto example, however I figured my mistake out, it was on a filter command above this.
      Thanks for your assistance Aaron.