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


相关推荐

  • idea企业开发之插件推荐

    idea企业开发之插件推荐推荐在企业开发中,使用IntelliJIDEA时常使用到的插件。

    2022年6月6日
    58
  • mvc与三层结构终极区别[通俗易懂]

    mvc与三层结构终极区别[通俗易懂]注:本文章内所有内容都来自互联网,本人主要是起了一个收集的作用http://www.cnblogs.com/zhhh/archive/2011/06/10/2077519.html又看到有人在问三层架构和MVC的关系,感觉这种问题有点教条化了。因为它们都在逻辑上将应用程序划为三块,凑了一个数字3,就有人非要把它们联系到一起了。  这两个东西我接触有几年了,有一点体会,表达一下:

    2022年6月25日
    20
  • Redis – 11、集群(Cluster)

    Redis – 11、集群(Cluster)redis集群是对redis的水平扩容,即启动N个redis节点,将整个数据分布存储在这个N个节点中,每个节点存储总数据的1/N。

    2025年7月27日
    4
  • jquery下载教程[通俗易懂]

    jquery下载教程[通俗易懂]jquery下载教程建议使用google浏览器下载,不建议使用IE浏览器(没有办法生成.js文件,只能复制粘贴)第一种方法第二种方法

    2022年6月6日
    33
  • linux安装p12,用命令行安装mobileprovision和p12证书

    linux安装p12,用命令行安装mobileprovision和p12证书我这边使用python来编写的,基本达到了最大化程度的解耦,其他人或者其他地方都可以直接使用。先创建installMobileProfile.py#!/usr/bin/python#-*-coding:UTF-8-*-importsysimportcommandsimportosparamsCount=len(sys.argv)if(paramsCount!=5):prin…

    2022年6月22日
    53
  • 代码在线编辑工具_php代码编辑器安卓版

    代码在线编辑工具_php代码编辑器安卓版在线代码编辑器    在线编辑各种文本形式的源代码,如js,html,php等,要支持语法高亮,即时输入即时高亮。 我的初步想法是用一个来实现,就是类似于常见的在线网页编辑器,但是因为仅仅是需要代码编辑,所以,要控制只能输入文本,不能让用户插入图片啊链接啊等等东西,感觉比较难。 希望大家能够探讨一下如何实现。 Bespin

    2022年8月14日
    7

发表回复

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

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