Windows API GetShortPathName GetLongPathName

函数原型:

The GetShortPathName function retrieves the short path form of a specified input path.

DWORD GetShortPathName(
                                                LPCTSTR lpszLongPath,  // null-terminated path string
                                                LPTSTR lpszShortPath,  // short form buffer
                                                DWORD cchBuffer        // size of short form buffer,in TCHARs
                                               );

The GetLongPathName function converts the specified path to its long form. If no long path is found, this function simply returns the specified name.
DWORD GetLongPathName(
                                                LPCTSTR lpszShortPath, // file name
                                                LPTSTR lpszLongPath,   // path buffer
                                                DWORD cchBuffer        // size of path buffer,in TCHARs
                                              );

说明:
这两个函数是用来把传入的路径转换为相对应的长路径或者短路径的,传入的路径要必须存在,否则会转换失败。
写一个程序事例:

int _tmain(int argc, _TCHAR* argv[])
{
	WCHAR szShort[MAX_PATH] = { 0 };
	WCHAR szFullPath[MAX_PATH] = TEXT("D:\\桌面\\MP3\\英语\\hommesick.mp3");
	DWORD dwShortBytes = GetShortPathName(szFullPath, szShort, MAX_PATH);

	WCHAR wszLongPath[MAX_PATH] = { 0 };
	DWORD dwLongBytes = GetLongPathName(szShort, wszLongPath, MAX_PATH);

	WCHAR szPath[MAX_PATH] = { 0 };
	GetModuleFileName(NULL, szPath, MAX_PATH);

	WCHAR wszLong[MAX_PATH] = { 0 };
	DWORD dwLong = GetLongPathName(szPath, wszLong, MAX_PATH);

}

 结果:
Windows API   GetShortPathName   GetLongPathName - Prairie - work labor and play

分析:
可见szShort被转化为短格式的路径,还可以得出并不是所有的路径都可以被转化的,传入的路径本身已经为长路径或者短路径 ,而调用GetLongPathName或者GetShortPathName的话,则不会转换

转载于:https://www.cnblogs.com/priarieNew/p/9756150.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值