Why does File.Exists ("c: \ filename.txt /") return true?

For file C:\filename.txt ,

 File.Exists(@"c:\filename.txt/"); 

returns true . But when we try to open this file name, it fails.

The file name is bad because of the trailing. But how can we check if the file is really valid, as this tells me that this is not only normal, but also that the file exists.

Update: Results are expected (false) in a standard command line test application. But in my custom uri handler, the .Exists () file returns true. This is really weird.

+6
source share
1 answer

Typically, when you request a system folder, file visualization is the culprit of this kind of problem. IE file exists in virtual storage, but not in the real requested path. As a result, an attempt to open it will fail. So, before you indicate that the file does not exist., You must make sure that it does not exist.

+1
source

Source: https://habr.com/ru/post/957940/


All Articles