This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can trysigning in orchanging directories.
Access to this page requires authorization. You can trychanging directories.
Retrieves the final path for the specified file.
For more information about file and path names, seeNaming a File.
DWORD GetFinalPathNameByHandleA( [in] HANDLE hFile, [out] LPSTR lpszFilePath, [in] DWORD cchFilePath, [in] DWORD dwFlags);
[in] hFile
A handle to a file or directory.
[out] lpszFilePath
A pointer to a buffer that receives the path ofhFile.
[in] cchFilePath
The size oflpszFilePath, inTCHARs. This value must include aNULL termination character.
[in] dwFlags
The type of result to return. This parameter can be one of the following values.
Value | Meaning |
---|---|
| 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 bylpszFilePath, inTCHARs. This value does not include thesize of the terminating null character.
Windows Server 2008 and Windows Vista: For the ANSI version of this function,GetFinalPathNameByHandleA, the return valueincludes the size of the terminating null character.
If the function fails becauselpszFilePath is too small to hold the string plus theterminating null character, the return value is the required buffer size, inTCHARs. 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, callGetLastError.
Return code | Description |
---|---|
| 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 volumeGUID path to identify it. This return value can also be returned if you are searching for a volumeGUIDpath on a network share. VolumeGUID paths are not created for networkshares. |
| Insufficient memory to complete the operation. |
| Invalid flags were specified fordwFlags. |
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.
Note
Windows 10 version 1709 and later and Windows Server version 1709 and later support theFileNormalizedNameInformation information class via SMB. See the [MS-SMB2 specification] (/openspecs/windows_protocols/ms-smb2/a64e55aa-1152-48e4-8206-edd96444e7f7#Appendix_A_414) Appendix A, Section 3.3.5.20.1 for more information.
A final path is the path that is returned when a path is fully resolved. For example, for a symbolic linknamed "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, seeCreateFile.
In Windows 8 and Windows Server 2012, this function is supported by the following technologies.
Technology | Supported |
---|---|
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 use of theGetFinalPathNameByHandle function.
#include <windows.h>#include <tchar.h>#include <stdio.h>#define BUFSIZE MAX_PATHvoid __cdecl _tmain(int argc, TCHAR *argv[]){ TCHAR Path[BUFSIZE]; HANDLE hFile; DWORD dwRet; printf("\n"); if( argc != 2 ) { printf("ERROR:\tIncorrect number of arguments\n\n"); printf("%s <file_name>\n", argv[0]); return; } hFile = CreateFile(argv[1], // file to open GENERIC_READ, // open for reading FILE_SHARE_READ, // share for reading NULL, // default security OPEN_EXISTING, // existing file only FILE_ATTRIBUTE_NORMAL, // normal file NULL); // no attr. template if( hFile == INVALID_HANDLE_VALUE) { printf("Could not open file (error %d\n)", GetLastError()); return; } dwRet = GetFinalPathNameByHandle( hFile, Path, BUFSIZE, VOLUME_NAME_NT ); if(dwRet < BUFSIZE) { _tprintf(TEXT("\nThe final path is: %s\n"), Path); } else printf("\nThe required buffer size is %d.\n", dwRet); CloseHandle(hFile);}
Note
The fileapi.h header defines GetFinalPathNameByHandle as an alias that automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that is not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, seeConventions for Function Prototypes.
Requirement | Value |
---|---|
Minimum supported client | Windows Vista [desktop apps | UWP apps] |
Minimum supported server | Windows Server 2008 [desktop apps | UWP apps] |
Target Platform | Windows |
Header | fileapi.h (include Windows.h) |
Library | Kernel32.lib |
DLL | Kernel32.dll |
Was this page helpful?
Was this page helpful?