What is the difference between GetLongPathName and GetFullPathName in WinAPI?

To determine the canonical path to the file specified by the relative path, or the path containing \..\ in the middle, stackoverflow suggests using GetFullPathName() here or GetLongPathName() here .

What is the difference between these features?

The goal is to get the paths starting with the drive letter from relative paths (for example ..\someDir\someFile.txt and someOtherDir\someFile.txt ) and eliminate the extra \..\ from the paths (for example C:\dirA\dirB\..\someFile.txt C:\dirA\someFile.txt ).

+5
source share
1 answer

GetFullPathName resolves file names and relative path names in absolute paths by adding the current working directory of the calling process.

GetLongPathName only allows short (8.3) names for long names.

Note that the latter requires access to the disk, so the relative path is likely to be resolved using the current working directory.

TL; dr:
Call GetFullPathName to resolve the relative path to the absolute.
Call GetLongPathName to resolve the absolute path, which may contain a short (8.3) name for the long form of the name.


Be careful:

The current working directory is a resource of each process and can be changed, for example. in the standard file open dialog box. I would use this only to resolve command line arguments, which may be relative to the CWD in which the program was running.

A long path name length may not exist for every 8.3 named file.

+7
source

All Articles