`noterm` in `{sourcepath$|\|noterm}` doesn't work

For a command like Delete ERASEEMPTYSPACE={letter}:, you need to specify a drive letter. The docs don't show a final backslash. As it turns out, this command also works with a final backslash. But perhaps this won't be the case with every other command/context/external app, and {sourcepath$|\|noterm} logically should work as you'd expect it to, returning C:, e.g.

Drive roots always have the backslash added, since C: means something very different to C:\ in some contexts.

Convention in Windows is that backslash is always there in a path (unless specifying the current directory on a given drive, which is a concept dating back to MS-DOS that still survives in cmd.exe and maybe other corners of Windows).

You mean if |noterm removed the backslash, if |\ wasn't used, but the path was a root path, incorrect paths would be returned for most contexts?

An alternative would be to provide {dlet}/{dlet$} for all contexts, not just the status bar. This would also be more versatile, since some external command line programs could require just a letter without even the colon.

It's not pretty, but you can use this if you want just the drive letter and a colon when on a path below a drive letter:

{sourcepath|\|noterm|regex!="(^[A-Z]:)\\.*"|to="\1"}

(Or scripting, of course, which would be more straightforward in some ways but less in others. Depends what you want to do with it which makes most sense.)

Edit: Changed pattern for a better one.

You can also use the evaluator: {=left(sourcepath,2)=}

1 Like

Good to know this exists.

This seems better to me: {sourcepath$|\|regex="([A-Z]:)\\"|to="\1"|noterm}

  • (I don't know whether $ is strictly necessary in this case.)
  • The regex doesn't need to end in .*, since we use |\.
  • Docs flaw: The docs for the regex modifier should make it clearer that the whole pattern needs to match from start to end, or it won't work.
    • This also means ^ is unnecesary.
  • Docs flaw: The docs for noterm say: "Strips the trailing path separator from the returned path." But since the above expression needs |\ to not end in a backslash, even though we may leave the realm of paths when tampering via regexes, it rather seems to be the case that the absence of noterm is what's active by adding a final \, if the text shortly before returning doesn't already end in a backslash. Playing around with {sourcepath$|\|regex=".*"|to="a\\\\"|noterm} (changing usage of |noterm and number of backslashes after a) reveals this. So, noterm's docs are a bit misleading when it comes to use cases with regex. An additional note on the technical way to function (absence of noterm and such) would be appropriate.
    • Having |noterm at the very end is more reflective of the fact that its associated action is performed after the regex find-and-replace.

You can use notermdrive to strip the slash from drive roots as well (this was omitted from the documentation).

1 Like