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

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

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

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

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • 六、策略模式—旅行的交通工具 #和设计模式一起旅行#[通俗易懂]

    兵无常势,水无常形,能因敌变化而取胜者,谓之神! ——《孙子兵法》故事背景旅行开始,我和设计模式mm要去的目的地很多,去往不同目的地可以选择的交通工具也是多样的,从北京到上海,我们可以选择自驾游、乘坐飞机、高铁,甚至是骑单车等等方式!每一种交通工具到达目的的时间也不同,假如从北京到上海,乘坐飞机两个小时,高铁五个小时,自驾游3天(3*24小时),每一种交通费也不一样!假…

  • java 单例模式 —饿汉式懒汉式

    java 单例模式 —饿汉式懒汉式目录单例设计模式饿汉式懒汉式饿汉式vs懒汉式结语单例设计模式所谓单例设计模式,就是采取一定的方法在整个软件系统中,对某个类只能存在一个对象实例1、单例类只能有一个实例。2、单例类必须自己创建自己的唯一实例。3、单例类必须给所有其他对象提供这一实例。饿汉式饿汉式:在程序启动或单例模式类被加载的时候,单例模式实例就已经被创建。上例子!packagecom.happy.demo;publicclassSingleton…

  • spring spel表达式_Substring

    spring spel表达式_Substring1.什么是SpEL表达式SpEL表达式语言是一种表达式语言,是一种可以与一个基于spring的应用程序中的运行时对象交互的东西。有点类似于ognl表达式。总得来说SpEL表达式是一种简化开发的表达式,通过使用表达式来简化开发,减少一些逻辑、配置的编写。2.使用XML方式实现SpEL表达式

  • 统计学的卡方检验方法是什么呢?用几个生活实例带你揭秘!

    统计学的卡方检验方法是什么呢?用几个生活实例带你揭秘!作者|文文酱的数据课堂来源|知乎专栏https://zhuanlan.zhihu.com/p/69888032卡方检验,统计学的方法,现在机器学习看变量的时候也会用到。很多不知道…

  • idea激活 jetbrains-agent(jetbrains激活码)

    一、下载jar包JetbrainsCrack-2.7-release-str.jar百度这个jar包名字很多资源最好是找最新的二、找到软件的安装路径下的bin目录;将下载的jar包放到bin目录下,并将datagrip64.exe.vmoptions、datagrip.exe.vmoptions两个文件末尾添加一行代码-javaagent:C:\JetBrains\DataGri…

  • docker一键启动、关闭、删除命令

    docker一键启动、关闭、删除命令

发表回复

您的电子邮箱地址不会被公开。

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