Best way to escape backslashes?

I couldn't find any internal/script command or modifier to escape backslashes in paths, like for in JScript, but I highly doubt doing something like this is the best and cleanest way to go:

String(clickData.func.sourcetab.selected_files[0]).replace(/\\/g,"\\\\")
// or if the file already is in a variable:
String(file).replace(/\\/g,"\\\\")

Any better and cleaner solution? On one hand I'm afraid and on the other hand I really hope that I missed something.

Easier solution for using backslashes? No.
But alternatively you can use forward slashes, too: replace(/\\/g, '/'). DOpus, even Windows Explorer, has no problems with / in paths.

1 Like

You generally only need to escape backslashes in JScript string literals

If the strings are paths that come from other objects, they don’t need escaping.