Jump to content
  • Advertisement
Sign in to follow this  
BeanDog

Windows--Correct file path case?

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

If you intended to correct an error in the post then please contact us.

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 this post


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

DAP

Share this post


Link to post
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();
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!