PathFileExists用法--使用#include <shlwapi.h>

PathFileExists用法--使用#include <shlwapi.h>BOOLPathFileExists(LPCTSTRpszPath);Determinesifafileexists.—经检测,该函数可以检测文件或目录是否存在!RemarksThisfunctionteststhevalidityofthefileandpath.Itworksonlyonthelocal…

大家好,又见面了,我是你们的朋友全栈君。

BOOL PathFileExists(LPCTSTR pszPath);

         Determines if a file exists.

—经检测,该函数可以检测文件或目录是否存在!

Remarks

This function tests the validity of the file and path. It works only on the local file system or on a remote drive that has been mounted to a drive letter. It will return FALSE for remote file paths that begin with the UNC names \\server or \\server\share. It will also return FALSE if a mounted remote drive is out of service.

 

为了使用PathFileExists(),必须包含头文件”shlwapi.h”,范例代码如下:

?
#include <windows.h>
#include <iostream.h>
#include <shlwapi.h>
  
void
main(
void
)
{
    
// Valid file path name (file is there).
    
char
buffer_1[] =
"C:\\TEST\\file.txt"
; 
    
char
*lpStr1;
    
lpStr1 = buffer_1;
      
    
// Invalid file path name (file is not there).
    
char
buffer_2[] =
"C:\\TEST\\file.doc"
; 
    
char
*lpStr2;
    
lpStr2 = buffer_2;
      
      
    
// Search for the presence of a file with a true result.
    
int
retval = PathFileExists(lpStr1);
    
if
(retval == 1)
    
{
        
cout <<
"Search for the file path of : "
<< lpStr1 << endl;
        
cout <<
"The file requested \""
<< lpStr1 <<
"\" is a valid file"
<< endl;
        
cout <<
"The return from function is: "
<< retval << endl;
    
}
      
    
else
    
{
        
cout <<
"The file requested "
<< lpStr1 <<
" is not a valid file"
<< endl;
        
cout <<
"The return from function is: "
<< retval << endl;
    
}
      
    
// Search for the presence of a file with a false result.
    
retval = PathFileExists(lpStr2);
    
if
(retval == 1)
    
{
        
cout <<
"\nThe file requested "
<< lpStr2 <<
" is a valid file"
<< endl;
        
cout <<
"Search for the file path of: "
<< lpStr2 << endl;
        
cout <<
"The return from function is: "
<< retval << endl;
    
}
      
    
else
    
{
        
cout <<
"\nThe file requested \""
<< lpStr2 <<
"\" is not a valid file"
<< endl;
        
cout <<
"The return from function is: "
<< retval << endl;
    
}
}

编译后,却发现一个错误:error LNK2001: unresolved external symbol __imp__PathFileExistsA@4

网上搜索了下,发现是因为没有添加相应的lib。添加lib的方法网上有不少,这里使用下面的方法:

 PathFileExists用法--使用#include <shlwapi.h>

 这样,就可以通过编译了!

<Linker from : http://www.cnblogs.com/joeblackzqq/archive/2010/11/09/1872309.html>

转载于:https://www.cnblogs.com/MMLoveMeMM/articles/3095112.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/158065.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • directshow使用说明_ug对电脑的配置要求

    directshow使用说明_ug对电脑的配置要求另外,DirectX9.0c已经将DShow分离出去了,下载时请选DirectX9.0b或者一下再是配置DirectShow的VC开发环境一.第一步,设置INCLUDE及LIB目录 在把dxsdk中提供的baseclass编译通过后,用四种方式编译,会分别生成四个lib,一般只用到了 其中的Debug和Release文件,在tool|option|vc++dir

    2022年10月11日
  • java编程代码都是背下来的吗_向学弟学妹们介绍自己的大学

    java编程代码都是背下来的吗_向学弟学妹们介绍自己的大学同学们好,今天二哥是来还债的,记得先拖到文末点个赞再回来细细的读,好不好!最近一段时间,我一直在学习Java虚拟机和字节码方面的知识,为的就是有朝一日成为真正牛逼的技术大佬!不知道大家有没有这种感觉,就是一开始学习编程的时候,真心不想看底层的东西,就想直接上来撸代码,但时间久了以后,总感觉缺点啥~~~~于是我开始阅读《深入理解计算机系统》、《图解TCP/IP》、《深入理解Java虚拟机》这些偏底层的书籍,看得烦了,就去刷我之前给大家推荐过的两个视频课,《哈佛大学的CS50》和《计算机科学速成

    2022年10月30日
  • 使用谷歌搜索攻略_Google浏览器

    使用谷歌搜索攻略_Google浏览器由于谷歌被封,无法使用谷歌搜索。但是对于研发人员来说,很多问题只有在谷歌中才能找到答案。后来一朋友推荐了archsocks代理服务1、访问https://github.com/archsocks/archsocks链接,下载windows版本安装。 如果没有,附件中有安装文件2、按照readme中的操作步骤来操作。 3、配置pac代理。 首先打开网络网络和共享中…

    2022年9月4日
  • 产品需求管理[通俗易懂]

    产品需求管理[通俗易懂]第三课需求管理1需求管理是什么1.1需求挖掘:看四块,自己行业,总体趋势,未来方向,商业模式。最直接的需求一定来源于用户,用户访谈,用户反馈,调查问卷,社交平台。1.2需求匹配:需求挖掘解决发现

    2022年8月5日
  • UML——行为图

    UML——行为图UML——行为图

    2022年4月24日
  • 最简单的纯js实现点击展开二级菜单功能

    最简单的纯js实现点击展开二级菜单功能虽然,jQuery已经非常好用了,但是实际的开发项目中,还是有很多限制,比如项目组奇葩的要求,不能使用任何插件,当然,也是考虑插件占用资源,毕竟100+KB对与小型项目来说还是非常大的。我最近就遇到做个点击展开二级菜单的要求,当然只能用原生的JS去写来实现,我借鉴了网上的一个案例,补充一下,分享一下:如果,默认打开页面进来时二级菜单是隐藏的,需要点击才能展现二级菜单,再点击就是隐藏二级菜单。这

    2022年5月11日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号