I\'m working on a batch program that process a big amount of files (more than 50 000 files) and I\'m facing weird behavior with the Directory.GetFiles
method.
This is the expected behavior of the GetFiles method and it's same on Windows as well, if you search in directory with .pdf it will pick files with extensions .pdfa or *.pdfaaa, you would need to put a Where()
yourself like:
Directory.GetFiles(directory, "*.pdf").Where(item => item.EndsWith(".pdf"));
As you can see that when we search in windows It is giving the same result as your code was giving:
For the reason of why the GetFiles is behaving that way please have a look here and you might also want to look at this post as well
As explained by @luaan and by @hans-passant (thanks a lot !) I do not found the file with the .pdfa extension, because the 8.3 format is disabled on my hard drive.
On a hard drive with the 8.3 format enabled, the method behaves like stated in the doc.
The GetFiles has a different behavior with the setting enabled or not.