I believe that the easiest thing to do is P/Invoke the built-in StrCmpLogicalW() function in Windows, and call it within your IComparer's Compare function.
Just when using this function you should keep in mind that it’s behavior differs between different versions of windows S, so you need make sure that you check that carefully.
Here is an Example of how you can implement the whole thing within your code:
[SuppressUnmanagedCodeSecurity]
internal static class NativeMethods
{
[DllImport("shlwapi.dll", CharSet = CharSet.Unicode)]
public static extern int StrCmpLogicalW(string psz1, string psz2);
}
To use it to Sort order Strings:
public sealed class SimpleStringComparer : IComparer<FileInfo>
{
public int Compare(String a, String b)
{
return NativeMethods.StrCmpLogicalW(a, b);
}
}
To use it the Sort FileInfo Object instances directly:
public sealed class FileInfoNameComparer : IComparer<FileInfo>
{
public int Compare(FileInfo a, FileInfo b)
{
return NativeMethods.StrCmpLogicalW(a.Name, b.Name);
}
}