Customized copy of file name with path for FTP files

Customized copy of file name with path for FTP files

49
Basic UserBasic User
49

    Sep 29, 2014#1

    Hi Mofi,

    I was also wondering if it is necessary to separate the path from the filename with a |. Like this:

    FTP::account name\/home/user|my_remote_file.txt

    I use this feature a lot but I have to replace | with / everytime I use it. As a matter of fact, I normally need the path and filename only to send to someone via email. Don't need the string 'FTP::account name\'. Just need the portion /home/user/my_remote_file.txt. If there could be configuration option to control this, it will certainly be a big time saver.

    Thanks.

    6,681583
    Grand MasterGrand Master
    6,681583

      Sep 29, 2014#2

      I'm just a user like you and therefore can't answer your question. I really don't know why name of file is separated from path with character | in full name of a file loaded via FTP.

      But if you use Edit - Copy File Path/Name to copy the name of the active file, replace this command by a script added to the list of scripts with a hotkey or chord for fast execution.

      Code: Select all

      if (UltraEdit.document.length > 0)  // Is any file opened?
      {
         UltraEdit.selectClipboard(0);
         UltraEdit.clearClipboard();
         UltraEdit.clipboardContent = UltraEdit.activeDocument.path.replace(/^S?FTP::.*?\\(?:\/(?=\/))?(.*?)\|(.*?)$/i,"$1/$2");
      }
      As the replace method of JavaScript String object returns a copy of the string on not matching regular expression, this little scripts copies the file names of files on a drive (local or network) or on a remote computer loaded using UNC path unmodified to Windows clipboard. But the Windows clipboard contains instead of FTP::account name\/home/user|my_remote_file.txt the string /home/user/my_remote_file.txt for files loaded via FTP or SFTP.
      Best regards from an UC/UE/UES for Windows user from Austria

      49
      Basic UserBasic User
      49

        Sep 29, 2014#3

        Hi Mofi,

        Thanks a lot for the workaround and the script as such works just fine. However, I don't know how to:

        "replace this command by a script added to the list of scripts with a hotkey or chord for fast execution".

        If you could please elaborate on this or point me to the thread if it has already been answered.

        Thanks a lot...

        6,681583
        Grand MasterGrand Master
        6,681583

          Sep 30, 2014#4

          So you have pasted the few lines of this small script into a new ASCII/ANSI file and saved it for example with file name CopyFileName.js into a directory like %APPDATA%\IDMComp\UltraEdit\MyScripts. Which folder to use does not matter for UltraEdit.

          Open Scripting - Scripts and use button Add to add the script CopyFileName.js to the list of scripts. You can enter also a short description for this script if the file name itself is not meaningful enough.

          Then left click into column Hotkey and press the key or key combination you want to use for executing this script. If you want to use a multi-key assignment like Ctrl+Shift+S as primary hotkey for all scripts and one more key like c for executing CopyFileName.js, left click now on column Chord and press the additional key.

          Close the Scripts dialog with button OK.

          There is now CopyFileName.js in menu Scripting for execution. The script can be executed now also from View - Views/Lists - Script List which can be for example docked with auto-hide setting enabled on left or right side. But most likely you run the script with the hotkey/chord.

          It is not really necessary, but advisable, to remove the hotkey assignment on command EditCopyFilePathToClipboard at Advanced - Configuration - Key Mapping if the hotkey of this command is now assigned to the script for a customized Copy File Path/Name.
          Best regards from an UC/UE/UES for Windows user from Austria

          49
          Basic UserBasic User
          49

            Sep 30, 2014#5

            Hi Mofi,

            thanks a lot for the detailed explanation. Yesterday, I had copied your code to a script named ftpcopyfilename.js and added to the Scripts menu. I was able to execute it with the hotkey I assigned to it, in my case Alt+/ and it worked perfectly.

            Now one last thing. Can I assign this script to a toolbar button?

            Thanks a lot.

            6,681583
            Grand MasterGrand Master
            6,681583

              Sep 30, 2014#6

              I have explained already all 3 possibilities to run a script. It is not possible to run a script or macro from toolbar as there are no commands for script or macro execution.
              Best regards from an UC/UE/UES for Windows user from Austria

              49
              Basic UserBasic User
              49

                Sep 30, 2014#7

                OK. Thanks a lot for all your help.

                  Nov 04, 2014#8

                  Hi Mofi,

                  I am back with another question on this topic.

                  I am having a slight issue with this script. What happens is that if I copied something to the clipboard in my MS Word document then the script does not replace the contents of the clipboard that is already there. I have tried several times but it doesn't seem to work.

                  If I use UltraEdit "copy" command once before using the script, then it works fine.

                  Any thoughts on this please?

                  Thanks.

                  6,681583
                  Grand MasterGrand Master
                  6,681583

                    Nov 04, 2014#9

                    I could not reproduce such a problem using MS Word 2010 and the UltraEdit script. But in real there are multiple clipboard formats and I do not know if UltraEdit clears all of them before writing a string to the clipboard of format CF_TEXT, see MSDN article about the Clipboard Formats.

                    I updated my script in the post above by inserting line UltraEdit.clearClipboard(); I can only hope that this is an improvement on your problem.

                    And you should be aware of special Office Clipboard as used by Microsoft Office applications. Text copying between UltraEdit and MS Word can be done only via Windows system clipboard.
                    Best regards from an UC/UE/UES for Windows user from Austria

                    49
                    Basic UserBasic User
                    49

                      Nov 04, 2014#10

                      Hi Mofi,

                      It is possible that MS Word 2010 behaves differently that MS Word 2003. I tried with both MS Word and Microsoft Outlook and I can recreate the problem all the time. UltraEdit.clearClipboard() didn't help. I do have a workaround i.e. click on "copy" icon BEFORE running the script. This way it work OK.

                      Thank you for your help again.

                      6,681583
                      Grand MasterGrand Master
                      6,681583

                        Nov 28, 2014#11

                        I tried the script today on Windows XP x86 with MS Word 2003 and there was no problem. I could always paste in Microsoft Word 2003 what the UltraEdit script copied to Windows clipboard. Are you sure that you don't use Office Clipboard feature in Word 2003?

                        However, here is a another version of the script:

                        Code: Select all

                        if (UltraEdit.document.length > 0)  // Is any file opened?
                        {
                           sFileName = UltraEdit.activeDocument.path.replace(/^S?FTP::.*?\\(?:\/(?=\/))?(.*?)\|(.*?)$/i,"$1/$2");
                           UltraEdit.newFile();
                           UltraEdit.activeDocument.write(sFileName);
                           UltraEdit.activeDocument.selectToTop();
                           UltraEdit.selectClipboard(0);
                           UltraEdit.activeDocument.copy();
                           UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
                        }
                        It writes the file name of active file to a new file, selects the file name in the new file, copies the file name to Windows clipboard and closes the new file without saving.

                        The regular expression was also modified to avoid 2 slashes at beginning of path of an FTP loaded file.
                        Best regards from an UC/UE/UES for Windows user from Austria