Can't reverse back to shortpath?

D.D.K-2637 966 Reputation points
2024-07-21T22:47:39.6433333+00:00

Hi,

I have this folder path in short-form like this

C:\Users\admin\Downloads\NEWFOL~2\NEWFOL~1\...\NEWFOL~1

using GetLongPathName, then I have

C:\Users\admin\Downloads\New folder (2) - Copy - Copy test\New folder\...\New folder

but now using GetShortPathName,

length = GetShortPathName(lpszPath, NULL, 0); //with getlasterror=0

the length alway return 0;

seems like the lpszPath is too long causing it to fail, if I remove some characters in lpszPath to <256, now it works.

Is there a way to reclaim the original short path?

Thanks you!

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,649 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,755 questions
{count} votes

1 answer

Sort by: Most helpful
  1. David Lowndes 2,545 Reputation points MVP
    2024-07-21T22:58:58.46+00:00

    As noted in the documentation:

    "By default, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, prepend "\\?\" to the path."

    Have you tried doing that?

    3 people found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.