tripbrock
tripbrock

Reputation: 960

Directory.Exists on a folder in Program Files fails

I simply have this bit of code.

string path = @"C:\Program Files (x86)\My App\Sub Folder of my App\";

if(Directory.Exists(path)) {
   MessageBox.Show("It's here!");
} else {
   MessageBox.Show("Can't find it!");
}

Now the folder does exist and running the command:

explorer "C:\Program Files (x86)\My App\Sub Folder of my App\"

Opens up the window, yet in my code it fails to see the folder. If I had any hair I would be pulling it out.

Any suggestions as to why this is happening?

Upvotes: 2

Views: 1429

Answers (1)

Bruno Silva
Bruno Silva

Reputation: 3097

Using "@" you don't need to escape the backslash character (\).

string path = "C:\\Program Files (x86)\\My App\Sub Folder of my App\\";

My initial answer was incorrect, but I'm keeping the answer as it might be useful to others.

Upvotes: 3

Related Questions