术语 | getfullpathname |
释义 | GetFullPathName 语法: C++ DWORD WINAPI GetFullPathName( __in LPCTSTR lpFileName, __in DWORD nBufferLength, __out LPTSTR lpBuffer, __out LPTSTR *lpFilePart ); GetFullPathName函数 检索的完整路径和文件指定的文件名。 作为一个要执行此操作的事务操作,请使用GetFullPathNameTransacted功能。 有关文件和路径名信息,请参阅文件名,路径和命名空间。 注意GetFullPathName函数不建议多线程应用程序或共享库代码。有关详细信息,请参见备注部分。 参数 lpFileName [in] 该文件的名称。 此参数可以是一个短(8.3形式)或长文件名。此字符串也可以是共享或卷名。 在此函数的ANSI版本,名称被限制为MAX_PATH字符。为了延长此限制,以32,767宽字符,调用的功能和前面加上“\\ Unicode版本\\?\\”的路径。有关更多信息,请参见命名一个文件。 nBufferLength [in] 缓冲区的大小收到空终止的驱动器和路径TCHARs,字符串。 lpBuffer [out] 阿一个缓冲区,它接收空终止的驱动器和路径字符串指针。 lpFilePart [out] 阿一个缓冲区,它接收的地址(在lpBuffer)最后文件的路径名组成部分的指针。 此参数可以为NULL。 如果lpBuffer指的是一个目录,而不是一个文件,lpFilePart接收为零。 返回值 如果函数成功,返回值是长度,TCHARs,复制到lpBuffer字符串,不包括终止空字符。 如果lpBuffer缓冲区太小包含的路径,返回值的大小,在TCHARs,认为须持有的路径和终止空字符缓冲区。 如果该函数的任何其他原因而失败,返回值是零。为了获得更多错误信息,调用GetLastError。 备注 GetFullPathName合并与指定文件名当前驱动器的名称和目录,以确定完整路径和文件指定文件名。它也将计算出的完整路径文件名部分的地址和文件名 此函数不验证,最终的路径和文件名是有效的,或者说他们看到一个对相关卷现有的文件。 请注意,lpFilePart参数不需要字符串缓冲区空间,但仅限于一个单一的地址不够的。这是因为它简单地返回一个缓冲区内已经存在的lpBuffer地址。 份额和销量的名称是有效的输入lpFileName。例如,下面的列表标识返回的路径和文件名,如果测试- 2是远程计算机和U:映射的驱动器是一个网络: 如果您指定“\\ \\测试2 \\ q $ \\ lh”返回的路径是“\\ \\测试2 \\ q $ \\ lh” 如果您指定“\\ \\?\\联合国军司令部\\测试2 \\ q $ \\ lh”返回的路径是“\\ \\?\\联合国军司令部\\测试2 \\ q $ \\ lh” 如果您指定“未决定:”返回的路径是“未决定:\\” GetFullPathName不转换指定的文件名,lpFileName。如果指定的文件名存在,您可以使用GetLongPathName或GetShortPathName转为长或短的路径名,分别为。 如果返回值是比nBufferLength指定的值大,您可以再次调用该函数的缓冲区足够大,以保存路径。有关此除了使用零长度为动态分配缓冲区的案例,请参阅示例代码部分。 注意:尽管在这种情况下返回值是一个长度,其中包括终止空字符,就成功返回值不包括终止在伯爵空字符。 多线程应用程序和共享库中的代码不应该使用GetFullPathName职能,并应避免使用相对路径名。当前目录国家的SetCurrentDirectory函数书面存储为每个进程中的全局变量,因此,多线程应用程序不能可靠地使用数据,没有腐败的可能从其它线程这个值,也可以读取或设置此值。这种限制也适用于SetCurrentDirectory和GetCurrentDirectory功能。唯一的例外是当应用程序保证是在一个线程中运行,例如解析命令行中的主线程参数字符串之前产生任何额外的线程文件名。多线程应用程序中使用相对路径名或共享库的代码可以产生不可预知的结果,不支持。 实例 下面的C + +的例子显示了GetFullPathName,GetLongPathName和GetShortPathName基本用途。又例如使用动态分配,见GetShortPathName。 #include #include #include #define BUFSIZE 4096 #define LONG_DIR_NAME TEXT("c:\\\\longdirectoryname") void _tmain(int argc, TCHAR *argv[]) { DWORD retval=0; BOOL success; TCHAR buffer[BUFSIZE]=TEXT(""); TCHAR buf[BUFSIZE]=TEXT(""); TCHAR** lppPart={NULL}; if( argc != 2 ) { _tprintf(TEXT("Usage: %s [file]\\n"), argv[0]); return; } // Retrieve the full path name for a file. // The file does not need to exist. retval = GetFullPathName(argv[1], BUFSIZE, buffer, lppPart); if (retval == 0) { // Handle an error condition. printf ("GetFullPathName failed (%d)\\n", GetLastError()); return; } else { _tprintf(TEXT("The full path name is: %s\\n"), buffer); if (lppPart != NULL && *lppPart != 0) { _tprintf(TEXT("The final component in the path name is: %s\\n"), *lppPart); } } // Create a long directory name for use with the next two examples. success = CreateDirectory(LONG_DIR_NAME, NULL); if (!success) { // Handle an error condition. printf ("CreateDirectory failed (%d)\\n", GetLastError()); return; } // Retrieve the short path name. retval = GetShortPathName(LONG_DIR_NAME, buf, BUFSIZE); if (retval == 0) { // Handle an error condition. printf ("GetShortPathName failed (%d)\\n", GetLastError()); return; } else _tprintf(TEXT("The short name for %s is %s\\n"), LONG_DIR_NAME, buf); // Retrieve the long path name. retval = GetLongPathName(buf, buffer, BUFSIZE); if (retval == 0) { // Handle an error condition. printf ("GetLongPathName failed (%d)\\n", GetLastError()); return; } else _tprintf(TEXT("The long name for %s is %s\\n"), buf, buffer); // Clean up the directory. success = RemoveDirectory(LONG_DIR_NAME); if (!success) { // Handle an error condition. printf ("RemoveDirectory failed (%d)\\n", GetLastError()); return; } } 要求: 最低支持:client-Windows 2000专业版 最低支持server-Windows 2000服务器 HeaderWinBase.h(头文件:winuser.h) LibraryKernel32.lib DLLKernel32.dll Unicode和ANSI namesGetFullPathNameW(Unicode)和GetFullPathNameA(ANSI)的 参见 文件管理函数 GetFullPathNameTransacted GetLongPathName GetShortPathName GetTempPath SearchPath 如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com) 生成日期:2009年9月3日 ==英文原文==GetFullPathName Function Retrieves the full path and file name of the specified file. To perform this operation as a transacted operation, use the GetFullPathNameTransacted function. For more information about file and path names, see File Names, Paths, and Namespaces . Note The GetFullPathName function is not recommended for multithreaded applications or shared library code. For more information, see the Remarks section. Syntax C++ DWORD WINAPI GetFullPathName( __in LPCTSTR lpFileName, __in DWORD nBufferLength, __out LPTSTR lpBuffer, __out LPTSTR *lpFilePart ); Parameters lpFileName [in] The name of the file. This parameter can be a short (the 8.3 form) or long file name. This string can also be a share or volume name. 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 . nBufferLength [in] The size of the buffer to receive the null-terminated string for the drive and path, in TCHARs. lpBuffer [out] A pointer to a buffer that receives the null-terminated string for the drive and path. lpFilePart [out] A pointer to a buffer that receives the address (within lpBuffer) of the final file name component in the path. This parameter can be NULL. If lpBuffer refers to a directory and not a file, lpFilePart receives zero. Return Value If the function succeeds, the return value is the length, in TCHARs, of the string copied to lpBuffer, not including the terminating null character. If the lpBuffer buffer is too small to contain the path, the return value is the size, in TCHARs, of the buffer that is required to hold the path and the terminating null character. If the function fails for any other reason, the return value is zero. To get extended error information, call GetLastError . Remarks GetFullPathName merges the name of the current drive and directory with a specified file name to determine the full path and file name of a specified file. It also calculates the address of the file name portion of the full path and file name This function does not verify that the resulting path and file name are valid, or that they see an existing file on the associated volume. Note that the lpFilePart parameter does not require string buffer space, but only enough for a single address. This is because it simply returns an address within the buffer that already exists for lpBuffer. Share and volume names are valid input for lpFileName. For example, the following list identities the returned path and file names if test-2 is a remote computer and U: is a network mapped drive: If you specify "\\\\test-2\\q$\\lh" the path returned is "\\\\test-2\\q$\\lh " If you specify "\\\\?\\UNC\\test-2\\q$\\lh" the path returned is "\\\\?\\UNC\\test-2\\q$\\lh" If you specify "U:" the path returned is "U:\\" GetFullPathName does not convert the specified file name, lpFileName. If the specified file name exists, you can use GetLongPathName or GetShortPathName to convert to long or short path names, respectively. If the return value is greater than the value specified in nBufferLength, you can call the function again with a buffer that is large enough to hold the path. For an example of this case in addition to using zero-length buffer for dynamic allocation, see the Example Code section. Note Although the return value in this case is a length that includes the terminating null character, the return value on success does not include the terminating null character in the count. Multithreaded applications and shared library code should not use the GetFullPathName function and should avoid using relative path names. The current directory state written by the SetCurrentDirectory function is stored as a global variable in each process, therefore multithreaded applications cannot reliably use this value without possible data corruption from other threads that may also be reading or setting this value. This limitation also applies to the SetCurrentDirectory and GetCurrentDirectory functions. The exception being when the application is guaranteed to be running in a single thread, for example parsing file names from the command line argument string in the main thread prior to creating any additional threads. Using relative path names in multithreaded applications or shared library code can yield unpredictable results and is not supported. Examples The following C++ example shows a basic use of GetFullPathName, GetLongPathName, and GetShortPathName. For another example using dynamic allocation, see GetShortPathName . #include #include #include #define BUFSIZE 4096 #define LONG_DIR_NAME TEXT("c:\\\\longdirectoryname") void _tmain(int argc, TCHAR *argv[]) { DWORD retval=0; BOOL success; TCHAR buffer[BUFSIZE]=TEXT(""); TCHAR buf[BUFSIZE]=TEXT(""); TCHAR** lppPart={NULL}; if( argc != 2 ) { _tprintf(TEXT("Usage: %s [file]\\n"), argv[0]); return; } // Retrieve the full path name for a file. // The file does not need to exist. retval = GetFullPathName(argv[1], BUFSIZE, buffer, lppPart); if (retval == 0) { // Handle an error condition. printf ("GetFullPathName failed (%d)\\n", GetLastError()); return; } else { _tprintf(TEXT("The full path name is: %s\\n"), buffer); if (lppPart != NULL && *lppPart != 0) { _tprintf(TEXT("The final component in the path name is: %s\\n"), *lppPart); } } // Create a long directory name for use with the next two examples. success = CreateDirectory(LONG_DIR_NAME, NULL); if (!success) { // Handle an error condition. printf ("CreateDirectory failed (%d)\\n", GetLastError()); return; } // Retrieve the short path name. retval = GetShortPathName(LONG_DIR_NAME, buf, BUFSIZE); if (retval == 0) { // Handle an error condition. printf ("GetShortPathName failed (%d)\\n", GetLastError()); return; } else _tprintf(TEXT("The short name for %s is %s\\n"), LONG_DIR_NAME, buf); // Retrieve the long path name. retval = GetLongPathName(buf, buffer, BUFSIZE); if (retval == 0) { // Handle an error condition. printf ("GetLongPathName failed (%d)\\n", GetLastError()); return; } else _tprintf(TEXT("The long name for %s is %s\\n"), buf, buffer); // Clean up the directory. success = RemoveDirectory(LONG_DIR_NAME); if (!success) { // Handle an error condition. printf ("RemoveDirectory failed (%d)\\n", GetLastError()); return; } } Requirements Minimum supported clientWindows 2000 Professional Minimum supported serverWindows 2000 Server HeaderWinBase.h (include Windows.h) LibraryKernel32.lib DLLKernel32.dll Unicode and ANSI namesGetFullPathNameW (Unicode) and GetFullPathNameA (ANSI) See Also File Management Functions GetFullPathNameTransacted GetLongPathName GetShortPathName GetTempPath SearchPath Send comments about this topic to Microsoft Build date: 9/3/2009 ==原始网址==http://msdn.microsoft.com/en-us/library/aa364963(VS.85).aspx\n |
随便看 |
|
windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。