In the Windows version of my current personal project, I'm looking to support extended length filepaths. As a result, I'm a little confused with how to use the GetFullPathNameW API to resolve the full name of a long filepath.
According to the MSDN (with regards to the lpFileName parameter):
In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\?\" to the path. For more information, see Naming a File.
If I'm understanding this correctly, in order to use an extended length filepath with GetFullPathNameW
, I need to specify a path with the \\?\
prefix attached. Since the \\?\
prefix is only valid before volume letters or UNC paths, this would mean that the API is unusable for resolving the full name of a path relative to the current directory.
If that's the case, is there another API I can use to resolve the full name of a filepath like ..\somedir\somefile.txt
if the resulting name's length exceeds MAX_PATH
? If not, would I be able to combine GetCurrentDirectory
with the relative filepath (\\?\C:\my\cwd\..\somedir\somefile.txt
) and use it with GetFullPathNameW
, or would I need to handle all of the filepath resolution on my own?
\\?\C:\my\cwd\..\somedir\somefile.txt
or\\?\..\somedir\somefile.txt
, so I tried both. The first correctly resolves to\\?\C:\my\somedir\somefile.txt
, (which answers part of my question) while the second incorrectly resolves to\\?\somedir\somefile.txt
. – CabrillaGetCurrentDirectory
, not_getcwd
, right? Assuming that's the case, you're saying thatGetCurrentDirectory
won't work for a long cwd path even if I useGetCurrentDirectoyW
with an adequately sized buffer from a process that was created withCreateProcess
'slpCurrentDirectory
parameter using the\\?\
prefix? if so, that's a really obnoxious limitation. – CabrillaCreateFile
then useGetFinalPathNameByHandleW
to resolve the path. Unfortunately that does require a file to actually exist, or the creation of a temp file at an arbitrary spot on your drive. – JaclinGetFullPathName
is entirely string-based; it's just doing string manipulation on what you give it + whatever the current directory is. The paragraph about \\?\ is just boilerplate copy & paste - the function doesn't actually care what strings you pass it. – Dollhouse