System.IO.Abstractions icon indicating copy to clipboard operation
System.IO.Abstractions copied to clipboard

MockDirectory.EnumerateFiles search pattern behaves differently from Directory.EnumerateFiles in .NET 5+

Open Gav-Brown opened this issue 3 years ago • 2 comments

In .NET 5 the behaviour of the file extension search pattern changed from .NET Framework. See EnumerateFiles, specifically the table entry

book.xls, book.xlsx | *.xls | book.xls | book.xls, book.xlsx

To Reproduce Steps to reproduce the behaviour:

  1. Create files a.txt and b.txt2 in a directory.
  2. Run Directory.EnumerateFiles(dir, "*.txt", SearchOption.AllDirectories)
  3. Compare .NET 5 or 6 behaviour to MockDirectory

Expected behaviour Only a.txt should be returned.

Actual behaviour Both a.txt and b.txt2 are returned.

Can also just use *.t as search pattern which should return no files in a folder of .txt files etc.

Gav-Brown avatar Oct 13 '22 09:10 Gav-Brown

Good find, thanks for the detailed explanation!

When fixing this we need to ensure that we keep the current behavior for .NET Framework (what about .NET Core?).

fgreinacher avatar Oct 14 '22 12:10 fgreinacher

Thanks, By the way, ignore the *.t test as this behaviour only applies to 3 letter extensions, I believe.

Gav-Brown avatar Oct 14 '22 12:10 Gav-Brown