Command-line start-up arguments that contain paths

April 16, 2015

Recently I was working on a console app; my start-up arguments looked like this:

CmdLineArgs

ArgumentOne “c:\tmp\” “c:\tmp2”

And I got an error with the following code:

[sourcecode lang=“csharp”] string argumentone = args[0]; string sourceDir = args[1]; string destinationDir = args[2];




Turns out that the \\" escapes the final quote of the second argument, and so the third line crashes because there were only two arguments.  The fix is simple:

ArgumentOne "c:\\tmp" "c:\\tmp2"


Profile picture

A blog about one man's journey through code… and some pictures of the Peak District
Twitter

© Paul Michaels 2022