Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does GetFullPathName work with relative paths longer than MAX_PATH?

Tags:

winapi

The documentation for GetFullPathName() says that in order to use paths longer than MAX_PATH (260 characters) I need to prepend the file namespace prefix: \\?\. However, the general documentation on file names says that this prefix cannot be used with relative paths and thus a relative path's length is always limited to 260 characters. Does this mean there's no way to use GetFullPathName() with a relative path longer than MAX_PATH? (If so, then my understanding is that the function does not really support long paths unless the passed path is already a full one.)

like image 938
Mikhail Edoshin Avatar asked Jan 25 '15 14:01

Mikhail Edoshin


1 Answers

Agreed, that's nonsensical. The native api has no concept of relative paths, it is a pure winapi layer feature. It could be interpreted as a way to get the function to return the native path name. But it doesn't, I checked. Looks like a copy/paste doc bug.

Do keep your eye on the ball, when you need GetFullPathName() then you already lost anyway. Because GetCurrentDirectory() is already subject to the MAX_PATH limit. So long path support is already out of the window.

The generic advice is to never rely on relative paths, even if you don't care about long path support. Way too many accidents. With the only reasonable opt-out if you want to write a simple console mode app that is expected to be driven from the command line. And then you don't care because the command line interpreter is MAX_PATH encumbered.

like image 153
Hans Passant Avatar answered Sep 23 '22 05:09

Hans Passant