Win32 - get the real name of a file

Hi,

I'm looking for a way to get the real name of a file.

I have the following file "C:\MY_file.txt".

If I do CreateFile to open it with "C:\my_file.txt" as parameter it works I get a valid handle because IMO win32 is not case-sensitive.

Then I would like to know that the real name is not "my_file.txt" but "MY_file.txt".

Any help is greatly appreciated.

Best Regards,

Bernard
I can't find the function I was looking for, but found this: GetFullPathName
http://msdn.microsoft.com/en-us/library/windows/desktop/aa364963%28v=vs.85%29.aspx
Sorry but it doesn't work.
@ OP: Would you care to elaborate? It works fine when I compile it. Are you getting an error? Is the result not what you expected? Is your application crashing?
So much for the new fancy stuff.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#ifdef _UNICODE
#undef _UNICODE
#undef UNICODE
#endif

#include <Windows.h>
#include <iostream>

int main()
{
	WIN32_FIND_DATA find_data = {};
	if (HANDLE hFindHandle = FindFirstFile("C:\\TEMP\\HELLO.CLASS", &find_data))
	{
		std::cout << "Real Name: " << find_data.cFileName << std::endl;
		std::cout << "8.3 name: " << find_data.cAlternateFileName << std::endl;

		FindClose(hFindHandle);
	}
	return 0;
}

Real Name: Hello.class
8.3 name: HELLO~1.CLA
Last edited on
Was in a hurry I apologize for my short answer.
Thanks kbw for the solution I appreciate it.
Registered users can post here. Sign in or register to post.