Skip to content

Backslashes and quotes at the end of a path

Dirk Rombauts edited this page Feb 22, 2018 · 1 revision

.NET apparently has a strange behavior when dealing with backslashes and quotes at the end of a path.

Consider this command line - pay attention to the -o argument

pickles.exe -df=dhtml -trfmt=nunit3 -f=C:\Tests\Features\ -o="C:\Testme2\" -lr="C:\Testme\Result.xml" -exp

This will result in an error, complaining about illegal characters in the path. The reason is explained in [.NET Gotcha] Commandline args ending in \" are subject to CommandLineToArgvW whackiness.

My take-away from it is:

  • If you use quotes to delimit a path, then don't finish the path with a backslash
  • If you have to finish the path with a backslash, then don't use quotes to delimit the path
  • If you must both finish the path with a backslash and use quotes to delimit the path, then escape the backslash

The escaped version looks like this - again pay attention to the -o argument:

pickles.exe -df=dhtml -trfmt=nunit3 -f=C:\Tests\Features\ -o="C:\Test me 2\\" -lr="C:\Test me\Result.xml" -exp
Clone this wiki locally