从一个文件路径获取一个文件名后缀。
函数声明:
PTSTR PathFindExtension(
_In_ PTSTR pszPath
);
参数:
PTSTR pszPath
可存储文件的整个完整路径或者一个文件名(有文件后缀名),但最大长度不超过 MAX_PATH ,以null字符结束。
返回:
若找到后缀名,则返回一个指针,该指针是以点(.)为前缀的扩展名的地址;反之,返回null字符的地址。
头文件:
shlwapi.h
库文件:
shlwapi.lib
其中PathFindExtensionW为unicode字符集函数,PathFindExtensionA为ANSI字符集函数。
实例:
#include <stdio.h>
#include <Shlwapi.h>
#pragma comment(lib, "shlwapi.lib")
int main()
{
char path[] = "C:\\Windows\\System32/notepad.exe";
LPCSTR name;
LPCSTR ext;
/* will output "notepad.exe" */
name = PathFindFileName(path);
ext= PathFindExtension(name);
printf("%s\n", name);
printf("%s\n", ext);
getchar();
return 0;
}
输出.exe: