This Question have 2 answers right now.

Getting actual file name (with proper casing) on Windows

By : NeARAZ
Source: Stackoverflow.com
Question!

Windows file system is case insensitive. How, given a file/folder name (e.g. "somefile"), I get the actual name of that file/folder (e.g. it should return "SomeFile" if Explorer displays it so)?

Some ways I know, all of which seem quite backwards:

  1. Given the full path, search for each folder on the path (via FindFirstFile). This gives proper cased results of each folder. At the last step, search for the file itself.
  2. Get filename from handle (as in MSDN example). This requires opening a file, creating file mapping, getting it's name, parsing device names etc. Pretty convoluted. And it does not work for folders or zero-size files.

Am I missing some obvious WinAPI call? The simplest ones, like GetActualPathName() or GetFullPathName() return the name using casing that was passed in (e.g. returns "program files" if that was passed in, even if it should be "Program Files").

I'm looking for a native solution (not .NET one).

By : NeARAZ


Answers

FindFirstFileNameW will work with a few drawbacks:

  • it doesn't work on UNC paths
  • it strips the drive letter so you need to add it back
  • if there are more than one hard link to your file you need to identify the right one
By : Doub


There is another solution. First call GetShortPathName() and then GetLongPathName(). Guess what character case will be used then? ;-)

By : sergioko



What happens when GetTickCount() wraps?

Win32: Modal dialog not returning focus

C/C++ USB drive event

How to hide an external program's windows programmatically?

How to download web resource using Digest authentication

Identify if a file(dll/exe) is locked or not by a process or library

windows process management


Discover if user has Admin rights

Differences between struct in C and C++

Split large file without copy?

What limits my use of the stack in terms of memory?

Video about Getting actual file name (with proper casing) on Windows