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


相关推荐

  • 华为s2700交换机配置vlan_同一交换机vlan互通

    华为s2700交换机配置vlan_同一交换机vlan互通原标题:华为S5700系列配置实例华为S5700系列配置一、#telnet远程登录步骤一:创建VLAN,并配置交换机VLAN的管理IP#创建vlansystem-view[Quidway]vlanxxx(vlanID)[Quidway-vlanID]quit#配置管理IP[Quidway]interfacevlanID[Quidway-VlanifID]ipaddress…

    2022年9月19日
    3
  • 至强e5处理器天梯图_e系列cpu天梯图

    至强e5处理器天梯图_e系列cpu天梯图lintel的至强CPU(Xeon)是为服务器准备的,优点核心数、线程数超多,对多任务处理优势明显,现在很多桌面电脑也会搭配志强CPU,用于游戏挂机,多任务处理等等。那么你们知道至强CPU性能排行榜,志强CPU中哪个最强,感兴趣的朋友一起来看看至强系列cpu天梯图,由本站2020年6月发布。至强CPU单线程跑分和多线程跑分性能排行榜:至强系列cpu天梯图2020:(数据比较多,大家可以使用CTR…

    2022年9月20日
    2
  • 布朗运动 金融学_布朗运动数学定义

    布朗运动 金融学_布朗运动数学定义作者:郑连虎来源:阿虎定量笔记正文:巴舍利耶:金融数学之父——要点:布朗运动、有效市场假说即使在信息爆炸的今天,想要了解法国数学家路易斯·巴舍利耶(LouisBachelier,1870-1946)的生活,依然缺乏资料。同许多思想超前的开拓者一样,巴舍利耶的研究成果在当时未能引起学界重视,直至50多年后被保罗·萨缪尔森…

    2022年9月30日
    1
  • Query $.each用法

    Query $.each用法Query each 用法以下内容非原创 来自百度文库 http wenku baidu com view 4796b6145f0e html nbsp 通过它 你可以遍历对象 数组的属性值并进行处理 使用说明 each 函数根据参数的类型实现的效果不完全一致 1 遍历对象 有附加参数 each Object function p1 p2

    2025年8月25日
    4
  • aria2 bt tracker_ar接入路由器产品文档

    aria2 bt tracker_ar接入路由器产品文档vi/root/trackers-list-aria2.sh内容如下:#!/bin/bash#/usr/sbin/servicearia2stoplist=`wget-qO-https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt|awkNF|sed”:a;N;s/…

    2022年9月28日
    4
  • 海量数据存储技术与解决方案[通俗易懂]

    海量数据存储难点:数据量过大,数据中什么情况都可能存在;软硬件要求高,系统资源占用率高;要求很高的处理方法和技巧。海量数据存储处理经验:一、选用优秀的数据库工具    现在的数据库工具厂家比较多,对海量数据的处理对所使用的数据库工具要求比较高,一般使用Oracle或者DB2,微软公司最近发布的SQLServer2005性能也不错。另外在BI领域:数据库,数据仓库,多维数据库,数据挖

    2022年4月14日
    54

发表回复

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

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