Hi!
One of my scripts (JS button script) uses the RENAME
command in a .RunCommand()
call.
It takes the full paths of selected files "p" and renames them to a new name "n".
var cmd = "RENAME FROM \""+ p + "\" TO \"" + n + "\" IGNOREEXT";
ClickData.func.command.RunCommand(cmd);
The above creates commands looking like this:
RENAME FROM "C:\\test name.txt" TO "test" IGNOREEXT
which is working fine in most cases.
Today, however, I tried renaming files that contained brackets ([
, ]
), and the command was ineffective.
It feels like DOpus might think this is a pattern to be matched, so I tried escaping the brackets by replacing them with themselves, preceded by an apostrophe '
, as per the documentation:
RENAME FROM "C:\\'[test'] name.txt" TO "test" IGNOREEXT
This did not work.
I tried different things, such as:
- Using different escape chars (
\
,`
) - Escaping the whole string like a RegExp string (Prepending special characters with a backslash via
str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
- Only escaping the opening brackets (in case that disqualifies the pair as a pattern sequence, and the second apostrophe is already interpreted as a literal apostrophe - because they are valid characters for Windows files and folders, too)
How do I do this?
I wish there was a way to just let DOpus know that it shouldn't try to interpret the FROM argument as a pattern to be parsed but a literal filename.