News:

MultiCommander v16.6 is released!

Main Menu

Copy path with spaces

Started by Bernd, November 21, 2020, 16:34:04

Previous topic - Next topic

Bernd

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)

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

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)

create a UserDefinedCommand of MultiScript Type

insert this script code
@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)

#4
Or we can do it even more efficent

@var $text = ArrayToString(GetSelectedFileNames(), "\r\n", 0 );
$text = StrReplace($text, " ", "%20");
SetClipboardText($text);

Bernd

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

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)

Quote from: 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?

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)

Quote from: Mathias (Author) on November 22, 2020, 13:36:21
Quote from: 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?

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