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


相关推荐

  • FFmpeg从入门到精通笔记之二

    FFmpeg从入门到精通笔记之二FFmpeg中常用的工具主要是ffmpeg、ffprobe、ffplay,它们分别用作多媒体的编解码工具、内容分析工具和播放器。ffmpeg常用命令ffmpeg的封装转换。ffmpeg的封装转换(转封装)功能包含在AVFormat模块中,通过libavformat库进行Mux和Demux操作.  *多媒体文件的格式有很多种,这些格式中的很多参数在Mux与Demux的操作参数中是公用的,…

    2022年6月26日
    29
  • 部门年终会议如何开_关于召开年度工作总结会议的通知

    部门年终会议如何开_关于召开年度工作总结会议的通知前言:最近有同学问我,部门年终总结会议要不要开,是否有这个必要?那我就说说我的观点,关注我的同学都知道我上月初刚参加完团队的年终总结,我想我应该很有发言权!部门年终总结会议有必要开吗?一、这是否有你的心理?二、那到底要不要开?三、个人感慨!一、这是否有你的心理?每年的年终,不仅个人要写年终总结,团队的leader也要复盘团队一年的工作情况以及来年的展望。很多人都会认为这个无非就是走个形式,给上面的领导看,基本没有任何意义,大家就无非聚集在一起,开个无聊的会,讲完后大家屁股一抬,工作的事全部重来!二

    2022年9月25日
    1
  • Bootstrap 之Table样式[通俗易懂]

    Bootstrap 之Table样式[通俗易懂]将标签添加class=‘table’类后的样式Table样式编号姓名年龄001郭靖25002黄蓉23003杨过24我们可以看到,Tabl

    2022年9月20日
    2
  • 2cu监控app下载_安卓2.2系统下载

    2cu监控app下载_安卓2.2系统下载环境要求HttpRunner是一个基于Python开发的测试框架,可以运行在macOS、Linux、Windows系统平台上。这里使用macOS系统进行演示对于python版本要求:py

    2022年7月29日
    6
  • stringbuffer stringbuilder区别_javastringbuffer

    stringbuffer stringbuilder区别_javastringbufferString、StringBuffer和StringBuilder的区别:文章目录StringStringBufferStringBuilderStringBuffer是如何实现线程安全的呢?Java9的改进String  String类是不可变类,即一旦一个String对象被创建以后,包含在这个对象中的字符序列是不可改变的,直至这个对象被销毁。  这个是String类的解释,之前小咸儿看…

    2022年4月19日
    50
  • 什么是移动端开发【重点学习系列—干货十足–一万字详解】

    什么是移动端开发【重点学习系列—干货十足–一万字详解】引言这一篇文章主要对移动端开发相关的基础知识点,进行总结。从移动端开发的一些概念、专有名词、缩放、viewport移动端事件、适配问题以及一些工作中沟通经常会用到这些方面来说一下移动端1-移动端开发相关概念移动端特点移动端与PC端网页有所不同,有以下几个特点小屏幕触摸交互屏幕尺寸繁多屏幕大小​屏幕大小指屏幕的对角线的长度,单位一般是英寸。常见的手机屏幕大小3.5、4…

    2022年6月24日
    38

发表回复

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

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