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


相关推荐

  • Mysql命令_MySQL alter

    Mysql命令_MySQL alter基于Mysql5.7版本的explain参数详解…Mysql官网相关参数解读一:idSELECT标识符1.id越大越先执行2.相同id,从从往下执行二:select_type1.SIMPLE:最简单的查询(没有关联查询没有子查询没有union的查询语句)2:PRIMARY:子查询最外层的查询语句3.SUBQUERY:子查询内层查询语句4.DERIVED:派生表查询,FROM后的不是表而是查询后的结果集5.UNION:union或unionall中的第二个以后的查询表6.U

    2025年12月3日
    3
  • GoogleEarth出新版-4.2版【含天际地图和中文版】「建议收藏」

    GoogleEarth出新版-4.2版【含天际地图和中文版】「建议收藏」GoogleEarth终于发布4.2版了,强烈建议大家去下载这个版本,因为这个版本不仅有繁体中文的支持,而且还包含了一个有趣的东西:GoogleSky(天际地图)。

    2022年7月3日
    34
  • php7 什么意思,php7新特性

    php7 什么意思,php7新特性1 trait 将类作为代码块引入 EasySwoole Core AbstractInte Singleton php 文件 namespaceEas Core AbstractInte traitSinglet privatestati instance staticfuncti args if isset se

    2026年3月17日
    2
  • springbean生命周期通俗一点_spring为啥是单例模式

    springbean生命周期通俗一点_spring为啥是单例模式一、Spring核心模块介绍1.SpringCore:Core封装包是框架的最基础部分,提供IOC和依赖注入特性。这里的基础概念是BeanFactory,它提供对Factory模式的经典实现来消除对程序性单例模式的需要,并真正地允许你从程序逻辑中分离出依赖关系和配置。2.SpringContext:构建于Core封装包基础上的Context封装包,提供了一种框架式的对象访问方法,有些象JNDI注册器。Context封装包的特性得自于Beans封装包,并添加了对国际化(I18N).

    2026年1月21日
    8
  • oracle: linux下启动、关闭oracle服务

    oracle: linux下启动、关闭oracle服务1 先登录服务器后 切换到 oracle 用户状态下 suoracle2 检查 oracle 监听器运行状态 lsnrctlstatu 命令查看 表示监听没有启动 3 执行启动监听 通过命令 lsnrctlstart lsnrctlstop 关闭监听 表示端口已启动成功 4 如果启动报错 listener ora 文件打开 调整 HOSTIP5 进入 sqlplus 命令 sqlplus n

    2026年3月17日
    2
  • 软件项目管理案例分析

    软件项目管理案例分析高水平项目管理是软件项目成功的关键,也是软件产品质量的根本保证,具有这方面理论和实践的人员是目前软件组织中急需的高层次人才。为建立符合中国国情的软件开发过程和组织体系,培训中心特举办“软件项目管理案例分析”培训班,具体事宜通知如下:一、培训对象软件开发机构高级管理人员、项目经理、系统架构师、系统分析师、资深开发人员、质量保证人员以及其他对提升软件开发质量负有责任的人员。二、学员基础

    2022年5月22日
    40

发表回复

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

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