Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Get the short name of any given path, I have already tried this using the below code but it gives same short path as long path.

CString sFilePath = _T("D:\\kn");
TCHAR szFilePath[100] = {0};
GetShortPathName(sFilePath, szFilePath, sizeof(szFilePath));
printf("%s\n", sFilePath);
printf("%s", szFilePath);
Posted
Comments
PIEBALDconsult 4-Dec-14 23:36pm    
Are you sure there is a short name?

hi,
Short paths are preferred not only when the path is lengthy but also when it has spaces in between like : C:\Temp\New Folder . So here the short path will be something like C:\Temp\New~1.

You are not testing with the correct path. Try with with some long path name or give a space in between .

hope this helps.
 
Share this answer
 
From MSDN GetShortPathName[^]:
Quote:
If the specified path is already in its short form and conversion is not needed, the function simply copies the specified path to the buffer specified by the lpszShortPath parameter.
Your example path "D:\kn" is already in the short form.
 
Share this answer
 
v2
A quick search found this discussion. http://stackoverflow.com/questions/843843/getshortpathname-unpredictable-results[^]

Apperently there is an issue with GetShortPathname not always delivering the expected results. Refer to the solution presented in the abovementioned discussion for a possible workaround.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900