core
core copied to clipboard
Directory.GetFiles Linux Case Sensitive
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.
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 })
Thanks for the workaround @svick , you saved my bacon.
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?
was this resolved in the later dotnet version?
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.