open from FTP - getting true filename into clipboard.

Help with writing and running scripts

open from FTP - getting true filename into clipboard.

Postby oracledba » Thu Apr 09, 2009 2:38 pm

The command "CopyFilePath" is great for local/network files.
However for FTP opened files, the string returned is not a "real" name that one can use at a OS prompt.
The string received is a special UE format of:
FTP::{yourftpaccount}\/path/path/path|filename.ext

Basically two search replace commands can convert the above into the true/correct filename.
1) remove everything between the "FTP::" and the "\" (backslash)
2) convert the vertical bar to a slash.

The following macro is somewhat functional but not perfect because it uses a temp file
the macrow as written may, (or may not), return you to the correct tab/edit point from which you came.

My questions are:
If I could find/replace within a clipboard I would have neither issue.
Is this possible?
Am I re-inventing the wheel here - does anyone have a better way?

Code: Select all
InsertMode
ColumnModeOn
HexOff
Clipboard 6
CopyFilePath
NewFile
Paste
Clipboard 0
UltraEditReOn
Find RegExp "FTP::*\"
Replace All ""
UltraEditReOn
Find "|"
Replace All "/"
Key HOME
Key SHIFT
StartSelect
Key END
EndSelect
Cut
CloseFile NoSave
User avatar
oracledba
Basic User
Basic User
 
Posts: 24
Joined: Wed Jan 19, 2005 12:00 am

Re: open from FTP - getting true filename into clipboard.

Postby sklad2 » Thu Apr 09, 2009 8:31 pm

I was suprised by the copy filenamespaths not returning the correct path. I always edit them like, you. Seems like a simple fix for UE.
User avatar
sklad2
Advanced User
Advanced User
 
Posts: 58
Joined: Thu Mar 08, 2007 12:00 am

Re: open from FTP - getting true filename into clipboard.

Postby Mofi » Fri Apr 10, 2009 3:22 am

oracledba wrote:Does anyone have a better way?

I would do that with a script instead of a macro because within the script environment you can copy the name of the active file directly from the document array into a string variable, reformat it with a regular expression and copy the reformatted file name from the string variable into the clipboard. Assign the hotkey normally used for executing Edit - Copy File Path/Name to the script and you are done. Your script should copy local file names or unsaved file names as is into the clipboard, in other words everything not starting with FTP:: is simply copied from the string variable into the clipboard.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4055
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: open from FTP - getting true filename into clipboard.

Postby oracledba » Mon Apr 13, 2009 11:23 am

Mofi - I did not understand the power of scripting and have completly ignored the fact that UE has this ability.
Thank you for pointing out that UE scripting exists.
WOW! What was I thinking - scripting is great!. Thanks again for pointing this out.

The following code is my first attempt at scripting.
It is simple but seemingly effective.

If anyone wants it - Enjoy.

Code: Select all
// my_copyFilePath.js

/* This script exists because the ultraedit function "copyFilePath"
   returns the filename being edited in UE syntax not a native OS syntax.
   For local/network files the two are the same thing however for FTP opened files
   the UE syntax is unique and unusable from the native OS perspective.

   This JS script performs several search/replace commands converting the
   string returned into a string recognizable by the native OS.
   Its worth noting that the replace commands do not alter the clipboard contents
   when the string is NOT a ftp opened file. In other words - for local/network
   files this script will simply leave the clipboard populated with the
   correct copyFilePath value as returned from UE's copyFilePath function.

   The UE syntax for ftp files is:
         "FTP::[ue-ftp-accountname]\/path/path/path|name.ext"
   to convert into native OS
    step 1) remove the "FTP::[ue-ftp-accountname]\"
    step 2) convert a the vertical bar to a slash.

   date       Name            Desc
   4/13/2009  xxxxxxxxx       Initial version

 */
UltraEdit.activeDocument.copyFilePath();
var clip = UltraEdit.clipboardContent;
clip = clip.replace(/^FTP::.*\\/, "");
clip = clip.replace(/\|/, "/");
UltraEdit.clipboardContent = clip;
User avatar
oracledba
Basic User
Basic User
 
Posts: 24
Joined: Wed Jan 19, 2005 12:00 am

Re: open from FTP - getting true filename into clipboard.

Postby sklad2 » Mon Apr 13, 2009 12:01 pm

Since I am doing a lot of UNIX work, I like this alot.

Thanks,
Steven :mrgreen:
User avatar
sklad2
Advanced User
Advanced User
 
Posts: 58
Joined: Thu Mar 08, 2007 12:00 am


Return to Scripts