Multi Commander Support Forum

Multi Commander => Support and Feedback => Topic started by: Bernd on November 21, 2020, 16:34:04

Title: Copy path with spaces
Post by: Bernd 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
Title: Re: Copy path with spaces
Post by: Mathias (Author) 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



Title: Re: Copy path with spaces
Post by: Matthias515566 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".
Title: Re: Copy path with spaces
Post by: Mathias (Author) 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.
Title: Re: Copy path with spaces
Post by: Mathias (Author) 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);
Title: Re: Copy path with spaces
Post by: Bernd 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)
Title: Re: Copy path with spaces
Post by: Bernd 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?
Title: Re: Copy path with spaces
Post by: Mathias (Author) 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
Title: Re: Copy path with spaces
Post by: Mathias (Author) 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