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:


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”

Profile picture

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

© Paul Michaels 2024