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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 史上最简单的 SpringCloud 教程 | 第一篇: 服务的注册与发现(Eureka)[通俗易懂]

    史上最简单的 SpringCloud 教程 | 第一篇: 服务的注册与发现(Eureka)[通俗易懂]springcloud为开发人员提供了快速构建分布式系统的一些工具,包括配置管理、服务发现、断路器、路由、微代理、事件总线、全局锁、决策竞选、分布式会话等等。它运行环境简单,可以在开发人员的电脑上跑。另外说明springcloud是基于springboot的。本文主要介绍了服务的注册与发现。

    2022年4月28日
    59
  • 未能连接一个windows服务器,Win7出现未能连接一个Windows服务的解决办法

    未能连接一个windows服务器,Win7出现未能连接一个Windows服务的解决办法近日有网友“所爱隔山海”Win7电脑在开机的时候遇到了开机很慢,开机后提示:未能连接一个Windows服务。如果遇到电脑出现未能连接一个Windows服务该如何解决呢?这就是小编今天要分享的一个电脑小技巧。Win7出现“未能连接一个Windows服务”错误提示,主要是由于电脑系统中的“SystemEventNotification”服务没有正常开启导致的,可能是用户在使用一些第三方安全软件优化…

    2022年5月14日
    75
  • 分享给有需要的你,精选了10套web开发免费视频教程~~

    分享给有需要的你,精选了10套web开发免费视频教程~~

    2021年10月14日
    47
  • linux修改用户名的命令_linux退出root用户命令

    linux修改用户名的命令_linux退出root用户命令Linux将用户名修改后,还需要修改组名+家目录+UID这只会更改用户名,而其他的东西,比如用户组,家目录,UID等都保持不变。1、修改用户名$usermod-l新用户旧用户  这只会更改用户名,而其他的东西,比如用户组、家目录、ID等都保持不变。注意: 你需要从要改名的帐号中登出并杀掉该用户的所有进程,要杀掉该用户的所有进程可以执行下面命令$s…

    2022年9月18日
    2
  • 0703-APP-Notification-statue-bar

    0703-APP-Notification-statue-bar

    2021年11月23日
    53
  • Canny算子边缘检测原理及实现

    Canny算子边缘检测原理及实现写在前面Canny边缘检是在在1986年提出来的,到今天已经30多年过去了,但Canny算法仍然是图像边缘检测算法中最经典、先进的算法之一。相比Sobel、Prewitt等算子,Canny算法更为优异。Sobel、Prewitt等算子有如下缺点:没有充分利用边缘的梯度方向。 最后得到的二值图,只是简单地利用单阈值进行处理。而Canny算法基于这两点做了改进,提出了:基于边缘梯度…

    2022年5月7日
    75

发表回复

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

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