Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File not found Exception.. But it's there

Tags:

Hey this is going to be one of those dumb questions. I am trying to pick up a file on my local system and I keep getting a FileNotFoundException thrown.

Someone set me straight please :)

if( File.Exists(@"C:\logs\hw-healthways-prod_2009-08-26.tar")) {      Console.WriteLine("Yay"); } else {      throw new FileNotFoundException();    } 

Tried moving the file into the same location as the executing application and did the following:

 if( File.Exists("hw-healthways-prod_2009-08-26.tar")) 

Same thing.

Then I made a random txt file and parked it there too.. "me.txt"

And it works?! So you thing the file name is the problem?

like image 837
Nick Avatar asked Aug 29 '09 00:08

Nick


1 Answers

Try doing Directory.GetFiles(@"C:\logs"). It's possible that the file in question has odd characters that are getting interpreted one way by Windows Explorer (presumably where you're reading "the file's property" from?) but a different way by the .NET Framework. This can happen if you have UTF-8 characters in the filename (perhaps an en dash?).

like image 60
Daniel Pryden Avatar answered Oct 12 '22 17:10

Daniel Pryden