Author Topic: Copy path with spaces  (Read 15428 times)

Bernd

  • Junior Member
  • **
  • Posts: 13
    • View Profile
Copy path with spaces
« on: November 21, 2020, 16:34:04 »
When I have a path "c:\Black and White" and copy it with Ctrl+P, MC copies it as it is, but I would like to have the spaces replaced with %20. Otherwise some programs don't recognize the complete path but stop after c:\Black. Is there a way to achieve this?
Best regards, Bernd

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4423
    • View Profile
    • Multi Commander
Re: Copy path with spaces
« Reply #1 on: November 21, 2020, 17:53:05 »
There is no built in function for that. But you can create you own UserDefinedCommand using MultiScipt

There are functions for getting name of selected files , replacing text in string for settings text to the clipboard.

http://multicommander.com/docs/UDC_multiscript
http://multicommander.com/docs/multiscript/functions/getfilefromview#getselectedfilenames
http://multicommander.com/docs/multiscript/functions/string#strreplace
http://multicommander.com/docs/multiscript/functions/misc#setclipboardtext




Matthias515566

  • Power Member
  • ****
  • Posts: 324
    • View Profile
Re: Copy path with spaces
« Reply #2 on: November 21, 2020, 17:55:09 »
copy your paths to excel or a text editorand use Search and Replace to change the Space with your old school HTML "%20".

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4423
    • View Profile
    • Multi Commander
Re: Copy path with spaces
« Reply #3 on: November 22, 2020, 01:02:15 »
create a UserDefinedCommand of MultiScript Type

insert this script code
Code: [Select]
@var $names = GetSelectedFileNames();
@var $count = arrayCount($names)
for($idx = 0; $idx < $count; $idx++)
{
   $names[$idx] = StrReplace($names[$idx], " ", "%20");
}

@var $text = ArrayToString($names, "\r\n", 0 );
SetClipboardText($text);

Save it, and assign a hotkey or add it to the menu.

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4423
    • View Profile
    • Multi Commander
Re: Copy path with spaces
« Reply #4 on: November 22, 2020, 01:04:25 »
Or we can do it even more efficent

Code: [Select]
@var $text = ArrayToString(GetSelectedFileNames(), "\r\n", 0 );
$text = StrReplace($text, " ", "%20");
SetClipboardText($text);
« Last Edit: November 22, 2020, 01:07:39 by Mathias (Author) »

Bernd

  • Junior Member
  • **
  • Posts: 13
    • View Profile
Re: Copy path with spaces
« Reply #5 on: November 22, 2020, 13:03:47 »
Thank you very much. I changed the script a little by using GetSelectedPaths() instead of GetSelectedFileNames() to get the combination of path/name and voilĂ : I have my first User Defined Command  8)

Bernd

  • Junior Member
  • **
  • Posts: 13
    • View Profile
Re: Copy path with spaces
« Reply #6 on: November 22, 2020, 13:20:30 »
While I am at it, I want to learn something...
How would I copy only the path name? I don't see a function for it. The only idea I have is to first get an array of all path/name, then of all names, then iterate through the arrays and use StrTrimRight() once to remove the names, then again to remove the \
Or I could use the StrRFind() command to find the first \ from the right and then trim the string with StrSub().
Any better ideas?

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4423
    • View Profile
    • Multi Commander
Re: Copy path with spaces
« Reply #7 on: November 22, 2020, 13:36:21 »
While I am at it, I want to learn something...
How would I copy only the path name? I don't see a function for it. The only idea I have is to first get an array of all path/name, then of all names, then iterate through the arrays and use StrTrimRight() once to remove the names, then again to remove the \
Or I could use the StrRFind() command to find the first \ from the right and then trim the string with StrSub().
Any better ideas?

Check out
http://multicommander.com/docs/multiscript/functions/getfilefromview

There are alot of function to get files names in many different ways.

And if that is not enougth you got lots of PathXXX function, that lets you manipulate paths. By getting parts of a full path.
http://multicommander.com/docs/multiscript/functions/filesystem#pathgetpathpart

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4423
    • View Profile
    • Multi Commander
Re: Copy path with spaces
« Reply #8 on: November 22, 2020, 13:38:55 »
While I am at it, I want to learn something...
How would I copy only the path name? I don't see a function for it. The only idea I have is to first get an array of all path/name, then of all names, then iterate through the arrays and use StrTrimRight() once to remove the names, then again to remove the \
Or I could use the StrRFind() command to find the first \ from the right and then trim the string with StrSub().
Any better ideas?

That path is normally the same for all selected files unless you are doing it from a search result.

Check out
http://multicommander.com/docs/multiscript/functions/getfilefromview
There are a lot of function to get files and paths names in many different ways.

And if that is not enough you got lots of PathXXX function, that lets you manipulate paths. By getting parts of a full path.
http://multicommander.com/docs/multiscript/functions/filesystem#pathgetpathpart