Skip to content

.NET 8 DirectoryInfo.EnumerateFiles with MatchCasing.CaseInsensitive fails on Linux #104096

Open
@Viech3

Description

@Viech3

Description

.NET 8.0.302
Ubuntu 22.04.3 LTS

Hi,

I have an Issue with DirectoryInfo.EnumerateFiles. It works fine on windows, but on Linux I have trouble with case insensitive searches.

When I search for "LOG/*.txt" I expect it to find "log/test.txt", but on Linux I get an "DirectoryNotFoundException": Could not find a part of the path '/home/user/publish/LOG'.

Reproduction Steps

Build and Execute following code on Linux:

namespace ConsoleApp1
{
    internal class Program
    {
        static void Main(string[] args)
        {
            if(!Directory.Exists("log"))
                Directory.CreateDirectory("log");

            if (!File.Exists("log/test.txt"))
                File.Create("log/test.txt").Dispose();

            var files = new DirectoryInfo(Environment.CurrentDirectory).EnumerateFiles("LOG/*.txt", new EnumerationOptions { MatchCasing = MatchCasing.CaseInsensitive });

            foreach (var file in files)
            {
                Console.WriteLine(file.FullName);
            }

            Console.WriteLine("Finished");
        }
    }
}

Expected behavior

Console displays "..../log/test.txt"

Actual behavior

Error is thrown:

Unhandled exception. System.IO.DirectoryNotFoundException: Could not find a part of the path '/home/user/publish/LOG'.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.IOdocumentationDocumentation bug or enhancement, does not impact product or test code

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions