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


相关推荐

  • fpga学习——zynq图像处理中的DVP流接口封装

    fpga学习——zynq图像处理中的DVP流接口封装之前文章介绍了基于zynq的图像处理架构问题。其中,作为开发者,需要重点关注图像传感器接口、处理算法、显示接口,这些模块。现在我们一同学习用于视频数据接口的DVP模块,并将其封装成AXI-stream接口便于直接和VDMAIP通信。DVP_AXIstreamIPv1.0使用说明1.设计概述•用于cmos传感器视频数据采集,将cmos输出的8位视频数据拼接成RGB565模式•AXI_stream主机接口,用于和PS端内存的数据交互•基于vivado18.3软件设计2.模块分析

    2022年5月31日
    72
  • oracle恢复数据库的正确方式,oracle恢复数据库方法详解

    oracle恢复数据库的正确方式,oracle恢复数据库方法详解1.第一:用安装数据库时的管理员用户登录:创建一个新的用户,如://创建用户123密码456createuser123identifiedby456;第二:授权,赋予dba的权限grantdbato123;第三:导入数据库imp123/456@orclfile=E:\*.DMPfull=y注意:orcl是你创建的数据库事例,在安装oracl的时候,默认会新建一个orc…

    2022年7月17日
    30
  • Django之Model操作

    Django之Model操作

    2022年4月2日
    44
  • oracle的union和union all_oracle count函数

    oracle的union和union all_oracle count函数定义了unionvar{uchartempa[4];ulongtemp3;};unionvarlongdat小编们利用C语言定义一个简单的Union共用体结构。你曾经喜欢小编,现在不喜欢了,小编不怪你,那是小编没本事。在这个结构中包含若干个属性,其中有Int、Char和Double型。谁是谁生命中的过客,谁是谁生命的转轮,前世的尘,今世的风,无穷无尽的哀伤的精魂。此时小编们…

    2022年10月26日
    0
  • LSTM模型搭建_LSTM神经网络

    LSTM模型搭建_LSTM神经网络defLSTM_Classifier(self,train,trainLabel,test,testLabel,val_test,val_label,new_test=None):train,test=np.array(train),np.array(test)train,test=train.reshape(train.shape[0],1,train.shape[1]),test.reshape(test.shape[0],1,tes…

    2022年9月11日
    0
  • Linux 下curl命令下Http 的get or post请求

    Linux 下curl命令下Http 的get or post请求

    2021年7月16日
    75

发表回复

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

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