PathIsPrefix 判断路径的包含关系

转载自:http://blog.csdn.net/morewindows/article/details/17078627

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

[cpp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. // 【MoreWindows工作笔记7】PathIsPrefix 判断路径的包含关系  
  2. //  http://blog.csdn.net/morewindows/article/details/17078627  
  3. #include <windows.h>  
  4. #include <Shlwapi.h>  
  5. #include <string>  
  6. #include <iostream>  
  7. using namespace std;  
  8. #pragma comment(lib, "shlwapi.lib")  
  9. int main()  
  10. {  
  11.   printf("   【MoreWindows工作笔记7】PathIsPrefix 判断路径的包含关系\n");      
  12.   printf(" - http://blog.csdn.net/morewindows/article/details/17078627 -\n");      
  13.   printf(" -- By MoreWindows( http://blog.csdn.net/MoreWindows ) --\n\n");    
  14.   string src_path = "C:\\test1\\test"//"\\home\\test1\\test";  
  15.   string des_path = "C:\\test1\\test2"//"\\home\\test1\\test2";  
  16.   if (PathIsPrefix(src_path.c_str(), des_path.c_str()))  
  17.     cout<<"目标路径: "<<des_path<<" 包含\n"<<"源路径:   "<<src_path<<endl;  
  18.   else  
  19.     cout<<"目标路径: "<<des_path<<" 不包含\n"<<"源路径:   "<<src_path<<endl;  
  20.   cout<<"-----------------------------------"<<endl;  
  21.   return 0;  
  22. }  
运行结果如图所示:


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值