Retrieves the final path for the specified file.
For more information about file and path names, see Naming a File.
DWORD GetFinalPathNameByHandleA( HANDLE hFile, LPSTR lpszFilePath, DWORD cchFilePath, DWORD dwFlags );
A handle to a file or directory.
A pointer to a buffer that receives the path of hFile.
The size of lpszFilePath, in TCHARs. This value does not include a NULL termination character.
The type of result to return. This parameter can be one of the following values.
||Return the normalized drive name. This is the default.|
||Return the opened file name (not normalized).|
This parameter can also include one of the following values.
If the function succeeds, the return value is the length of the string received by lpszFilePath, in TCHARs. This value does not include the size of the terminating null character.
Windows Server 2008 and Windows Vista: For the ANSI version of this function, GetFinalPathNameByHandleA, the return value includes the size of the terminating null character.
If the function fails because lpszFilePath is too small to hold the string plus the terminating null character, the return value is the required buffer size, in TCHARs. This value includes the size of the terminating null character.
If the function fails for any other reason, the return value is zero. To get extended error information, call GetLastError.
Can be returned if you are searching for a drive letter and one does not exist. For example, the handle
was opened on a drive that is not currently mounted, or if you create a volume and do not assign it a drive
letter. If a volume has no drive letter, you can use the volume GUID path to
This return value can also be returned if you are searching for a volume GUID path on a network share. Volume GUID paths are not created for network shares.
||Insufficient memory to complete the operation.|
||Invalid flags were specified for dwFlags.|
The Server Message Block (SMB) Protocol does not support queries for normalized paths. Consequently, when you call this function passing the handle of a file opened using SMB, and with the FILE_NAME_NORMALIZED flag, the function splits the path into its components and tries to query for the normalized name of each of those components in turn. If the user lacks access permission to any one of those components, then the function call fails with ERROR_ACCESS_DENIED.
A final path is the path that is returned when a path is fully resolved. For example, for a symbolic link named "C:\tmp\mydir" that points to "D:\yourdir", the final path would be "D:\yourdir".
The string that is returned by this function uses the \?\ syntax. For more information, see CreateFile.
In Windows 8 and Windows Server 2012, this function is supported by the following technologies.
|Server Message Block (SMB) 3.0 protocol||Yes|
|SMB 3.0 Transparent Failover (TFO)||Yes|
|SMB 3.0 with Scale-out File Shares (SO)||Yes|
|Cluster Shared Volume File System (CsvFS)||Yes|
|Resilient File System (ReFS)||Yes|
The following example demonstrates the us of the GetFinalPathNameByHandle function.
#include <windows.h> #include <tchar.h> #include <stdio.h>
|Windows version||Windows Vista [desktop apps | UWP apps] Windows Server 2008 [desktop apps | UWP apps]|
|Header||fileapi.h (include Windows.h)|