【MoreWindows工作笔记7】PathIsPrefix 判断路径的包含关系

工作后比较忙,没大块的时间来酝酿博客的写作,所以随时记点笔记,一来方便自己查阅,二来也督促自己学习和总结。如果能对大家有所帮助,就更加开心了大笑

判断路径的包含关系是Windows系统复制移动文件夹的前置条件,比如将C:\test复制到C:\test\test1下就是不可行的。前一篇《【MoreWindows工作笔记6】PathCommonPrefix 路径的公共前缀》介绍了使用函数提取路径的公共前缀,并使用公共前缀来判断路径的包含关系,本篇将介绍一个更简单的API函数来判断路径的包含关系——PathIsPrefix。下面请看完整的代码示范和运行结果:

// 【MoreWindows工作笔记7】PathIsPrefix 判断路径的包含关系
//  http://blog.csdn.net/morewindows/article/details/17078627
#include <windows.h>
#include <Shlwapi.h>
#include <string>
#include <iostream>
using namespace std;
#pragma comment(lib, "shlwapi.lib")
int main()
{
  printf("   【MoreWindows工作笔记7】PathIsPrefix 判断路径的包含关系\n");    
  printf(" - http://blog.csdn.net/morewindows/article/details/17078627 -\n");    
  printf(" -- By MoreWindows( http://blog.csdn.net/MoreWindows ) --\n\n");  
  string src_path = "C:\\test1\\test"; //"\\home\\test1\\test";
  string des_path = "C:\\test1\\test2"; //"\\home\\test1\\test2";
  if (PathIsPrefix(src_path.c_str(), des_path.c_str()))
    cout<<"目标路径: "<<des_path<<" 包含\n"<<"源路径:   "<<src_path<<endl;
  else
    cout<<"目标路径: "<<des_path<<" 不包含\n"<<"源路径:   "<<src_path<<endl;
  cout<<"-----------------------------------"<<endl;
  return 0;
}
运行结果如图所示:




地址:http://blog.csdn.net/morewindows/article/details/17078627  转载请标明出处,谢谢。

欢迎关注微博:http://weibo.com/MoreWindows  



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值