views:

291

answers:

3

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?

A: 

You may want to check your file permissions. Your computer may not have permission to the file.

Hmm.. I don't think so. I can open it manually.
Nick
+1  A: 

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?).

Daniel Pryden
Changing the name of the file seems to be the ticket.. Im looking into that. Thanks
Nick
A: 

C:\logs\hw-healthways-prod_2009-08-26.tar should be C:\\logs\\hw-healthways-prod_2009-08-26.tar. \ means the next character is an escape character.

Not when the string is prefixed with the @ character.
Daniel Pryden