# Windows--Correct file path case?

This topic is 4491 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Filenames and paths are not case-sensitive under Windows. But they *are* stored one way or the other on the file system, when you get right down to it. If I have a filename in all lowercase, is there a way to get the correct case as held in the file system? I prefer a .NET example, but any help would be greatly appreciated. I've tried:
if(File.Exists(strPath))
{
String strPathOnly = strPath.Substring(0, strPath.LastIndexOf('\\')+1);
String strFilename = strPath.Substring(strPath.LastIndexOf('\\')+1);
return(Directory.GetFiles(strPathOnly, strFilename)[0]);
}
else
return(strPath);

but it returns it in the case I gave it to the function. I tried a similar thing with the FileInfo class, but it again gave me back the same case I gave it. ~BenDilts( void );

##### Share on other sites
did u try FindFile (Win32, don't know what the .NET equivalent is
or if you have to import it)?

DAP

##### Share on other sites
You want to use GetLongFileName. I don't know if it's got a .NET equivalent but here's some sample code from pinvoke.net:

[DllImport("kernel32.dll", SetLastError=true, CharSet=CharSet.Auto)]static extern uint GetLongPathName(    string lpszShortPath,    [Out] StringBuilder lpszLongPath,    uint cchBuffer);public static string ToLongPathName(string shortName){    StringBuilder longNameBuffer = new StringBuilder(256);    uint bufferSize = (uint)longNameBuffer.Capacity;    GetLongPathName(shortName, longNameBuffer, bufferSize);    return longNameBuffer.ToString();}