PathFileExists用法--使用#include

PathFileExists用法--使用#includeBOOLPathFileExists(LPCTSTRpszPath);
        Determinesifafileexists.
—经检测,该函数可以检测文件或目录是否存在!Remarks
Thisfunctionteststhevalidityofthefileandpath.Itworksonlyonthelocalfilesystemoronaremotedrivethathasbeenmoun

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

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

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

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

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

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


相关推荐

  • git比较两个版本之间的区别

    git比较两个版本之间的区别

    2021年10月24日
    85
  • Mysql explain-type使用详解

    Mysql explain-type使用详解下面是测试用例,楼主的测试使用的MySQL版本是5.6.27-log。show createtableuser_man;CREATETABLE`user_man`( `manid`bigint(20)NOTNULLAUTO_INCREMENT, `manname`varchar(32)DEFAULTNULL, `manage`int(6)DEFAULTNULL…

    2022年10月17日
    3
  • 互联网圈内的域名大战[通俗易懂]

    互联网圈内的域名大战[通俗易懂]拥有1亿元人民币,我们可以买下一栋超级豪宅,一件绝世珍品,甚至是一家公司。360为如何花这笔钱提供了新思路:他们以1700万美元的天价,从沃达丰手中拿下了梦寐以求的域名360.com。为得到这颗皇冠上的明珠,360和沃达丰进行了长达3年的反复谈判,他们一度开出了1400万美元的高价却仍被对方拒绝。据说,双方是经过周鸿祎的朋友从中斡旋才以这个“相对优惠”的价码最终成交。域名,对于互联

    2022年9月28日
    2
  • 面试题jmeter怎么做性能测试_web测试面试题

    面试题jmeter怎么做性能测试_web测试面试题面试中遇到的问题:1.如何使用Jmeter进行并发测试2.如何设置并发量为10003.如果http请求每个都不一样,如何配置4.如何设置sessionID一、安装配置1.在Terminal中输入命令:ruby-e”$(curl-fsSLhttps://raw.githubusercontent.com/Homebrew/install/master/…

    2022年9月30日
    3
  • uCOSII操作系统移植笔记

    uCOSII操作系统移植笔记笔记一:今天粗略的看了一下周立功关于uc/osII在lpc2104上的移植方面的说明,这之中印象最深的应该是irq中断和软中断方面的处理,由于arm芯片的特殊性(拥有7种处理器模式),即每种处理器模式都有自己的堆栈,这样在处理堆栈的时候就会相应的麻烦一些。在响应异常时,该移植计划在初始代码里面比在没有操作系统的初始代码多了irq的处理,移植里面的irq处理多了由汇编语言编写的对任务环境的保存,

    2022年6月3日
    33
  • C语言switch语句用法_c语言switch语句格式

    C语言switch语句用法_c语言switch语句格式1、switch语句基本用法C语言中,switch语句是一种多分支选择语句,在实际应用中,要在多种情况中选择一种情况,执行某一部分语句。其使用一般形式如下:switch(表达式){case常量表达式1:语句块1;break;case常量表达式2:语句块2;break;……case常量表达式m:语句块m;break;default:语句块n;break;}使用说明如下:程序执行时,首先计算表达式的值,与case后面的常量表达式值比较,若相等就执行对应部分的语

    2022年8月30日
    1

发表回复

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

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