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:
c#
Directory.GetFiles(
path, pattern, new EnumerationOptions { MatchCasing = MatchCasing.CaseInsensitive })
Thanks for the workaround @svick , you saved my bacon.
Most helpful comment
That functionality already exists, you can use the overload of
Directory.GetFiles()acceptingEnumerationOptionsto specify case insensitive search:c# Directory.GetFiles( path, pattern, new EnumerationOptions { MatchCasing = MatchCasing.CaseInsensitive })