Skip to content

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

Open

Description

@Gav-Brown

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.

Activity

  1. added
    state: needs discussion
    type: bug
    on Oct 13, 2022
  2. fgreinacher commented on Oct 14, 2022

    @fgreinacher
    Contributor

    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?).

  3. added
    state: ready to pick
    area: testinghelpers
    and removed
    state: needs discussion
    on Oct 14, 2022
  4. Gav-Brown commented on Oct 14, 2022

    @Gav-Brown
    Author

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

  5. CaringDev commented on Nov 24, 2026

    @CaringDev
    Contributor

    @vbreuss I take it this could be closed given your fix?

  6. vbreuss commented on Nov 24, 2026

    @vbreuss
    Member

    @CaringDev : It fixes this issue in Testably.Abstractions, not here in System.IO.Abstractions (for more background on these two libraries, see here).

  7. CaringDev commented on Nov 24, 2026

    @CaringDev
    Contributor

    🙈 I haven't had enough coffee yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: testinghelpersstate: ready to picktype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions