Command-line start-up arguments that contain paths

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”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.