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)
上一篇 2022年7月12日 上午10:46
下一篇 2022年7月12日 上午10:46


相关推荐

  • Pytorch(一) Pytorch 的安装[通俗易懂]

    Pytorch(一) Pytorch 的安装[通俗易懂]安装步骤1.检查是否有合适的GPU,若有安装Cuda与CuDNN2.下载pytorch安装文件,进行pytorch的安装检查电脑是否有合适的GPU在桌面上右击如果能找到NVIDA控制面板,则说明该电脑有GPU。控制面板如下,并通过查看系统信息获取支持的Cuda版本点击帮助->点击系统信息弹出下面的对话框,在驱动程序版本那一栏就能看到该计算机使用的驱动版本。…

    2022年6月24日
    34
  • 小米手机-解BL锁+开ROOT权限

    小米手机-解BL锁+开ROOT权限在小米社区和网址https://miuiver.com/上,有MIUI的历史版本,还有刷机教程等等本文是参考上述的教程,并结合自己在刷机过程中,出现的问题进行记录并得到解决方案下面主要是,重要部分,同时还有一些容易出错的地方解BL锁要提前,在设置–更多设置–开发者模式–设备解锁状态中,绑定账号和设备,注意的地方,不要重复绑定设备,不然时间会重新计算的,吃亏了2次。只要登陆过一个小米账号,点击绑定一次即可。如果没有找到开发者模式,就先设置–我的设备–全部参数–.

    2022年6月10日
    74
  • 机器学习中的线性代数之矩阵求导

    机器学习中的线性代数之矩阵求导前面针对机器学习中基础的线性代数知识 我们做了一个常用知识的梳理 接下来针对机器学习公式推导过程中经常用到的矩阵求导 我们做一个详细介绍 矩阵求导 MatrixDeriva 也称作矩阵微分 MatrixDiffer 在机器学习 图像处理 最优化等领域的公式推导中经常用到

    2026年3月19日
    3
  • pychaem激活码【在线注册码/序列号/破解码】

    pychaem激活码【在线注册码/序列号/破解码】,https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月18日
    50
  • 谷歌浏览器驱动测试

    谷歌浏览器驱动测试selenium驱动谷歌浏览器,ip+headless+不出现自动测试字样importtimefromseleniumimportwebdriverfromselenium.webdriverimportChromeOptionsfromselenium.webdriver.chrome.optionsimportOptionsimportrequestsdefget_proxy():proxy=requests.get(“http://127.0.0

    2022年6月8日
    34
  • 移动端App开发流程管理

    移动端App开发流程管理前言刚刚做完一个项目,值得总结,在此记录一下。   欢迎加入学习小组QQ群: 156958554。项目流程一款应用的开发大体流程如下:1、项目立项:产品经理2、需求确认:产品经理(业务逻辑说明文档)3、业务确认:产品经理,技术经理,架构师4、业务架构:技术经理,架构师(业务流程文档)5、UI确认:产品经理,设计人员,开发人员全体6、

    2022年5月27日
    37

发表回复

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

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