With this program (cs.exe):
class Program
{
static void Main(string[] args)
{
foreach (var item in args)
{
Console.WriteLine(item);
}
}
}
And run:
> cs.exe go\to\a_path
go\to\a_path
> cs.exe "go\to\a path"
go\to\a path
> cs.exe "go\to\a path\"
go\to\a path"
> cs.exe 'go\to\a path\'
'go\to\a
path\'
That means if your path has a space so you quote it, be very careful NOT to put a trailing \ at the end, otherwise your program
might just not be able to handle it as it incorrectly contains a " at the end. Single quote is even weirder!
PowerShell exhibits a similar behavior but without the difference between single and double quotes.
How do I understand this behavior? What's the underlying rule to evaluate backslash in cmd so this can be explained consistently?
/at the end of any directory path myself as a clear note that it's a directory. I think it's just a limitation of the command line interpretation protocol @MC ND explained below, unfortunately.