Core: Directory.GetFiles Linux Case Sensitive

Created on 22 Apr 2020  路  2Comments  路  Source: dotnet/core

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.

Most helpful comment

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 })

All 2 comments

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.

Was this page helpful?
0 / 5 - 0 ratings