Extend COPYNAMES with forward slash

Please can you extend COPYNAMES with a parameter to get forward slashes instead of back slashes?

It's recommended to use e.g. "C:/MyDir/MySubdir" in e.g. Markdown documentation and many other software (e.g. R, Perl, etc.) incl. Windows cmd.exe itself supports "/" .. e.g. "cd /MyDir/MySubdir" works.

You can use the command's regex argument to swap \ for / easily.

Hm - I think I have problems with the DO regex syntax? :thinking:

Clipboard COPYNAMES=path REGEXP "\\#" "/"

doesn't change anything. Still returns the path with back slash.
Tried other things - without success. What's wrong?

The Perl version works fine.

perl -e "my $x='L:\MyDir\MySubDir'; print $x; $x =~ s/\\/\//g; print ' - ' . $x;"
L:\MyDir\MySubDir - L:/MyDir/MySubDir

clipboard copynames=path regexp (.*)\\(.*)# \1/\2

2 Likes

How do I add a forward slash to the end?
I tried several things. Or the function doesn't work anymore or it adds multiple slashes.
For example a path with 5 backward slashes adds ///// to the end.

That's because the pattern has a # on the end, which tells Opus to keep re-applying the regex until the string stops changing (or until it starts looping). So if you add the extra slash as part of the same pattern, you'll add one slash to the end for every backslash that the pattern replaces.

To add just a single slash, while still converting backslashes to slashes, use a second, separate pattern to add it, like this:

clipboard copynames=path regexp (.*)\\(.*)# \1/\2 .* \0/

Note that this will add the extra slash indiscriminately, even if the thing in the clipboard is a file path not a folder. You could add a modifier to make the button ignore files, or make it disabled if files are selected. Or you could use scripting to make the extra slash conditional on the type of item, if needed.

1 Like