News:

MultiCommander v16.6 is released!

Main Menu

Copying path to clipboard with forward slashes

Started by karthik, January 18, 2013, 08:46:33

Previous topic - Next topic

karthik

When we do a Ctrl+P, it copies the entire path to clipboard with backward slashes like C:\Users\Karthik\.. etc. Is there a way to copy the path with forward slashes like this C:/Users/Karthik/...

Since I am using this path in unix machines, having forward slashes will help greatly instead of me doing a find replace everytime.

Thanks.

Jungle


karthik


Jungle


karthik

I tried the following but doesn't seem to work:

@var $arr GetSelectedPaths();
LogDump($arr);
$arr = StrReplace($arr, "\" , "/");
SetClipboardText($arr);

In general, how do I debug a script. Where does the LogDump dump the output?

Jungle

#5
1. There is Multi-Script Debugger under Help menu
2. To see output in the Log window you should use Log function
3. $arr is Array, so in order to use it with StrReplace function you should either convert it to string or go through array in a loop.

UPD. Unfortunately, StrLinesArray2String function doesn't work for me, or maybe i use it incorrectly. So, probably, the only way is to make a loop. Maybe Mathias has the right solution.

Mathias (Author)

#6
Try this.

@var $arr = GetSelectedPaths();
@var $str = StrLinesArray2String($arr);
$str = StrReplace($str, "\" , "/");
SetClipboardText($str)


(You can compress it into two lines.)
@var $arr = GetSelectedPaths();
SetClipboardText( StrReplace( StrLinesArray2String( $arr ) , "\" , "/" ) );

Jungle

Quote from: Mathias (Author) on January 18, 2013, 13:07:18@var $str = StrLinesArray2String($arr);

That is why it didn't work for me. Declaration in the docs differs:

<str> StrLinesArray2String(<array> input, <num> eol);

Mathias (Author)

#8
Second parameter is optional so should work both with and without it.

(I will update the doc abort it being optional. )

Jungle

Quote from: Mathias (Author) on January 18, 2013, 13:30:20Second parameter is optional so should work both with and without it.

Very strange - now it works. Some time ago i got Error -1.

karthik

Thanks, Mathias and Jungle.

I can write similar scripts to get finename alone, path alone, etc. And I can assign shortcut hotkeys to these. suppose I assign the default
(Ctrl+P, Ctrl+Shift+P, Alt+Shift+P) shortcuts will it create any problems in terms of MC working and functions?

Is there a way by using multiscript I can get the output of Ctrl+P or Ctrl+Shift+P? In that case, I can use that (instead of GetSelectedPaths()) and replace the backward slashes by forward slashes.

Thanks.

Mathias (Author)

See Doc lots of function for getting different filename part

GetTargetFocusName() / GetTargetFocusName() will give you the current file that are in focus, without path



karthik

Thanks Mathias.

This works fine but when I select the ".." directory and execute this script I do not get the source path. Where as when I do Ctrl+P when ".." is selected I get the source path. Is there a way to modify the script to get the source path even for ".." directory with this script?

Essentially I am trying to have a replacement for Ctrl+P and make the script do whatever Ctrl+P will do but with forward slashes instead of backward slashes.

Thanks.

Mathias (Author)

Quote from: karthik on January 23, 2013, 05:31:58
Thanks Mathias.

This works fine but when I select the ".." directory and execute this script I do not get the source path. Where as when I do Ctrl+P when ".." is selected I get the source path. Is there a way to modify the script to get the source path even for ".." directory with this script?

Essentially I am trying to have a replacement for Ctrl+P and make the script do whatever Ctrl+P will do but with forward slashes instead of backward slashes.

Thanks.


If current item is the ".." item then get current path else get full path with filename, just like Ctrl+P

@var $path = GetSourceFocusName();

if( StrIsEqual($path,"..") )
{
   $path = GetSourcePath();
}
else
{
  $path = GetSourceFocusPath();
}

karthik