Author Topic: Copying path to clipboard with forward slashes  (Read 28291 times)

karthik

  • Active Member
  • ***
  • Posts: 56
    • View Profile
Copying path to clipboard with forward slashes
« on: January 18, 2013, 08:46:33 »
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

  • Contributor
  • VIP Member
  • *****
  • Posts: 540
  • Old Skull
    • View Profile
Re: Copying path to clipboard with forward slashes
« Reply #1 on: January 18, 2013, 09:25:17 »
MultiScript?

karthik

  • Active Member
  • ***
  • Posts: 56
    • View Profile
Re: Copying path to clipboard with forward slashes
« Reply #2 on: January 18, 2013, 09:33:13 »
Any pointers on how I could start?

Jungle

  • Contributor
  • VIP Member
  • *****
  • Posts: 540
  • Old Skull
    • View Profile
Re: Copying path to clipboard with forward slashes
« Reply #3 on: January 18, 2013, 10:45:40 »
Any pointers on how I could start?
Multi Commander Documentation > User Defined Commands and Scripting

karthik

  • Active Member
  • ***
  • Posts: 56
    • View Profile
Re: Copying path to clipboard with forward slashes
« Reply #4 on: January 18, 2013, 11:16:51 »
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

  • Contributor
  • VIP Member
  • *****
  • Posts: 540
  • Old Skull
    • View Profile
Re: Copying path to clipboard with forward slashes
« Reply #5 on: January 18, 2013, 12:24:49 »
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.
« Last Edit: January 18, 2013, 12:42:53 by Jungle »

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4416
    • View Profile
    • Multi Commander
Re: Copying path to clipboard with forward slashes
« Reply #6 on: January 18, 2013, 13:07:18 »
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 ) , "\" , "/" ) );
« Last Edit: January 18, 2013, 13:26:39 by Mathias (Author) »

Jungle

  • Contributor
  • VIP Member
  • *****
  • Posts: 540
  • Old Skull
    • View Profile
Re: Copying path to clipboard with forward slashes
« Reply #7 on: January 18, 2013, 13:13:48 »
@var $str = StrLinesArray2String($arr);

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

Code: [Select]
<str> StrLinesArray2String(<array> input, <num> eol);

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4416
    • View Profile
    • Multi Commander
Re: Copying path to clipboard with forward slashes
« Reply #8 on: January 18, 2013, 13:30:20 »
Second parameter is optional so should work both with and without it.

(I will update the doc abort it being optional. )
« Last Edit: January 18, 2013, 13:32:48 by Mathias (Author) »

Jungle

  • Contributor
  • VIP Member
  • *****
  • Posts: 540
  • Old Skull
    • View Profile
Re: Copying path to clipboard with forward slashes
« Reply #9 on: January 18, 2013, 13:39:46 »
Second parameter is optional so should work both with and without it.

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

karthik

  • Active Member
  • ***
  • Posts: 56
    • View Profile
Re: Copying path to clipboard with forward slashes
« Reply #10 on: January 18, 2013, 15:15:23 »
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)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4416
    • View Profile
    • Multi Commander
Re: Copying path to clipboard with forward slashes
« Reply #11 on: January 22, 2013, 15:00:40 »
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

  • Active Member
  • ***
  • Posts: 56
    • View Profile
Re: Copying path to clipboard with forward slashes
« Reply #12 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.

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4416
    • View Profile
    • Multi Commander
Re: Copying path to clipboard with forward slashes
« Reply #13 on: January 23, 2013, 07:21:32 »
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

Code: [Select]
@var $path = GetSourceFocusName();

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

karthik

  • Active Member
  • ***
  • Posts: 56
    • View Profile
Re: Copying path to clipboard with forward slashes
« Reply #14 on: January 23, 2013, 07:35:19 »
That helps a lot. Thanks much.