PathFileExists用法「建议收藏」

PathFileExists用法「建议收藏」BOOLPathFileExists(LPCTSTRpszPath);Determinesifafileexists.—经检测,该函数可以检测文件或目录是否存在!RemarksThi

大家好,又见面了,我是你们的朋友全栈君。

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用法「建议收藏」

 这样,就可以通过编译了!

<Linker from : http://www.cnblogs.com/joeblackzqq/archive/2010/11/09/1872309.html>

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/154321.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • centos7 top命令_linux tee命令

    centos7 top命令_linux tee命令top命令Linuxtop命令用于实时显示process的动态。top参数详解第一行,任务队列信息**系统当前时间:**13:52:56**系统开机后到现在的总运行时间:**up66

    2022年7月30日
    11
  • eruka快速刷新和kafka配置

    eruka快速刷新和kafka配置Kafkapartition扩充并且需要迁移数据生产不用指定具体分区,会自动分配拉取也不用指定具体分区,会自动拉多个分区可以同时拉取多个topickafka配置<dependency><groupId>org.apache.kafka</groupId><artifactId>kafka_2.12</artifactId><version>2.3.0</version>&lt…

    2022年8月21日
    7
  • AbstractQueuedSynchronizer_setcursel函数用法

    AbstractQueuedSynchronizer_setcursel函数用法executeScalar 用于查询    返回影响的行的第一行第一列ExecuteNonQuery 用于增、删、改? 返回受影响的行数

    2025年9月6日
    8
  • SQL注入报错注入函数[通俗易懂]

    SQL注入报错注入函数[通俗易懂]前言报错注入的前提是当语句发生错误时,错误信息被输出到前端。其漏洞原因是由于开发人员在开发程序时使用了print_r(),mysql_error(),mysqli_connect_error()函数将mysql错误信息输出到前端,因此可以通过闭合原先的语句,去执行后面的语句。常用报错函数updatexml()是mysql对xml文档数据进行查询和修改的xpath函数extractvalue()是mysql对xml文档数据进行查询的xpa…

    2022年9月30日
    2
  • RabbitMQ入门:在Spring Boot 应用中整合RabbitMQ

    在上一篇随笔中我们认识并安装了RabbitMQ,接下来我们来看下怎么在SpringBoot应用中整合RabbitMQ。先给出最终目录结构:搭建步骤如下:切换到amqp应用的控制台,能看到打印

    2022年2月16日
    40
  • 构建高并发高可用的电商平台架构实践[通俗易懂]

    构建高并发高可用的电商平台架构实践[通俗易懂]各个维度总结电商平台中的高并发高可用的架构实践,从架构设计的理念到平台的逻辑架构,以及到平台架构中各个模块的介绍

    2022年6月30日
    35

发表回复

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

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