This problem occurs when I try to hide a file in my directory with a tool named File Lock. This is not a regular hide as I can not see it in windows explorer.
Code:
string[] textFiles = Directory.GetFiles(@"c:\mydir")
//0 files returned
string[] textFiles = Directory.GetFiles(@"c:\mydir", "*.txt")
//1 file returned: "c:\mydir\."
File.Exists(textFiles[0])
//false
How can the second function return a “c:\mydir\.” file? I can remove all files that do not exist to solve my problem but I wonder why I get a “.” file in the first place.
I don’t have experience with the File Lock tool, but I can assume that it hooks FindFirstFile WinAPI function to protect some file from listing (that function is used by .NET Directory.GetFiles() function). And this hook can be written a little… buggy 🙂
Could you please try to disable the tool and redo your test?
Most likely you’ll solve the problem.
But If you get the same result, blame Directory.GetFiles().