-1

As the subject says - I'm trying to understand, why Directory.GetFiles only returns 1 result, when using asterisk in the SearchPattern.

For example, I'm trying to find all .nfo files in my directory, so I'm searching like this:

Directory.GetFiles(directory, "*.nfo");

But it always and only returns 1 hit even though, there's 2x nfo files in that directory - why ???

If I search like this:

Directory.GetFiles(directory, "*.*");

Then I get all files, including my 2x .nfo files.

Is this a known bug in Directory.GetFiles, or can anyone explain this ???

Thanks in advance.

PS: I've also tried to search using Directory.EnumerateFiles instead but with the same result... :(

  • What happens if you open a command prompt go to that directory and type `dir *.nfo`? – juharr May 21 '20 at 17:06
  • 1
    can you include the output from a console for dir /b *.nfo? It might make things clearer – Doug Dawson May 21 '20 at 17:08
  • Okay, this is strange - when I type `dir *.nfo` (or `dir /b *.nfo`, it doesn't matter) in a command prompt on my directory, I also only get 1 hit - I even tried to manually create a new/third .nfo file in there, but still only 1 hit in the CMD window - is this maybe a bug in Windows (I'm using Windows 10 LTSC with latest upgrades installed) ? – user1855026 May 21 '20 at 17:23
  • This is getting weirder - I also have 2x .jpg files in that folder, and when typing `dir *.jpg` I get no hits, but when typing `dir *.*`, I see all the files, including .jpg and .nfo. I've also tried to run CMD as administrator with no difference ... what's going on here ??? – user1855026 May 21 '20 at 17:39
  • It is probably working as designed. There's likely some nuance you're missing. – Doug Dawson May 21 '20 at 18:01
  • Though a workaround was found, this question is not really useful nor otherwise answerable without knowing what the actual contents are of that directory (i.e. the output of `dir /a /b`). – Lance U. Matthews Jul 07 '20 at 16:35

1 Answers1

0

I've managed to find a working solution by using the alternative code below.

Thanks for all ideas and suggestions :-)

Directory.GetFiles(directory, "*.*").Where(file => file.EndsWith(".nfo", StringComparison.OrdinalIgnoreCase));