Monthly Archives: April 2015

Command-line start-up arguments that contain paths

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:

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”