I\'m trying to write a static member function in C# or find one in the .NET Framework that will re-case a file path to what the filesystem specifies.
Example:
<
I have something more efficient but:
1) It doesn't seem to work for all cases. (I've not figured out the pattern of which files and directories it correctly gets the casing, and which ones it does not.)
2) It's Windows specific.
static string GetProperFilePathCapitalization1(string filename)
{
StringBuilder sb = new StringBuilder(260);
int length = GetLongPathName(filename, sb, sb.Capacity);
if (length > sb.Capacity)
{
sb.Capacity = length;
length = GetLongPathName(filename, sb, sb.Capacity);
}
if (0 == length)
throw new Win32Exception("GetLongPathName");
return sb.ToString();
}
[DllImport("kernel32.dll")]
static extern int GetLongPathName(string path, StringBuilder pszPath, int cchPath);