PathFindExtension

来源:互联网 发布:樱井知香番号全集 编辑:程序博客网 时间:2024/06/16 13:46

从一个文件路径获取一个文件名后缀。

函数声明:

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:


原创粉丝点击