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


相关推荐

  • 深入Redis客户端(redis客户端属性、redis缓冲区、关闭redis客户端)「建议收藏」

    深入Redis客户端(redis客户端属性、redis缓冲区、关闭redis客户端)「建议收藏」Redis数据库采用I/O多路复用技术实现文件事件处理器,服务器采用单线程单进程的方式来处理多个客户端发送过来的命令请求,它同时与多个客户端建立网络通信。服务器会为与它相连接的客户端创建相应的redis.h/redisClient结构,在这个结构中保存了当前客户端的相关属性及执行相关功能时的数据结构。I/O多路复用:linux有五类io模型1.阻塞2.非阻塞3…

    2022年6月10日
    29
  • 利用 JS 脚本实现网页全自动秒杀抢购

    利用 JS 脚本实现网页全自动秒杀抢购利用JS脚本实现网页全自动秒杀抢购倒计时页面:倒计时未结束时,购买按钮还不能点击。结束时,可以点击购买,点击后出现提示“付款成功”展示效果1.制作测试网页首先我们来做一个简易的抢购页面<!DOCTYPEhtml><htmllang=”zh_CN”><head><metacharset=”UTF-8″><title>Apple</title><styletype=”te

    2022年6月10日
    65
  • 计算机网络vlan的作用,计算机网络之九:VLAN

    计算机网络vlan的作用,计算机网络之九:VLAN一:什么是VLAN广播在网络中起着非常重要的作用,如发现新设备,调整网络路径,IP地址租赁等,许多网络协议都要用到广播。然而,随着网络内计算机数量的增多,广播包的数量也会急剧增加,当广播包的数量占到通讯总量的30%时,网络的传输效率将会明显下降。所以当局域网内的计算机达到一定数量后,通常采用划分VLAN(虚拟局域网)的方式将网络分隔开来。将一个大的广播域划分为若干个小的广播域,以减小广播可能造成的…

    2022年8月10日
    6
  • Mobx入门和较佳实践

    Mobx入门和较佳实践

    2021年6月18日
    106
  • 深度学习—2.常见的神经网络结构

    深度学习—2.常见的神经网络结构

    2021年10月5日
    48
  • POJ 2996 Help Me with the Game (模拟)

    POJ 2996 Help Me with the Game (模拟)题目链接:http://poj.org/problem?id=2996POJ训练计划中的模拟都是非常棒的模拟,也非常有代表性。这个题讲的是给你一个国际象棋棋盘,敲代码打印出黑白两方的棋子。以及棋子的坐标。可是须要注意的国际棋盘的坐标问题例如以下图这个国际棋盘能够看到数字轴和字母轴的方向以及增减关系。所以在这个题的统计的时候须要进行坐标转换。由于已经做过类似的方法…

    2022年8月12日
    10

发表回复

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

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