core icon indicating copy to clipboard operation
core copied to clipboard

Directory.GetFiles Linux Case Sensitive

Open jonmiller1 opened this issue 4 years ago • 4 comments

I'm using .NET 3.1.3 on Linux, specifically Raspbian. As an old windows .net programmer I expect search for files with Directory.GetFiles or File.Exists for the case not to matter. Since Windows doesn't allow you to have two files with the same name but different cases. Linux does allow this and it creates problems. I need a way to do a case insensitive File.Exists or at least a case insensitive search with Directory.GetFiles(). I've come up with a workaround but it seems like a helper method built-in to the Directory class would keep a lot of people from going through the same thing.

jonmiller1 avatar Apr 21 '20 23:04 jonmiller1

That functionality already exists, you can use the overload of Directory.GetFiles() accepting EnumerationOptions to specify case insensitive search:

Directory.GetFiles(
    path, pattern, new EnumerationOptions { MatchCasing = MatchCasing.CaseInsensitive })

svick avatar Apr 28 '20 11:04 svick

Thanks for the workaround @svick , you saved my bacon.

JimmyCushnie avatar Dec 29 '20 03:12 JimmyCushnie

There is no overload for File.Exists to handle this issue. I am checking dynamic file paths and cannot (easily) use Directory methods for my use case.

Any one have suggestions for using File.Exists across platforms with dynamic (read: "case in-sensitive human" provided) file paths? Is hacking something together with the Directory.GetFiles the only way for now?

itlackey avatar Feb 17 '21 22:02 itlackey

was this resolved in the later dotnet version?

joebnc avatar Apr 03 '23 05:04 joebnc

If https://github.com/dotnet/core/issues/4596#issuecomment-620550767 doesn't suit your needs please file an issue in https://github.com/dotnet/runtime/issues.

jozkee avatar Jul 16 '24 17:07 jozkee