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的方法网上有不少,这里使用下面的方法:

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

<Linker from : http://www.cnblogs.com/joeblackzqq/archive/2010/11/09/1872309.html>

转载于:https://www.cnblogs.com/MMLoveMeMM/articles/3095272.html

PathFileExists用法相关推荐

  1. PathFileExists用法--使用#include

    BOOL PathFileExists(LPCTSTR pszPath); Determines if a file exists. ---经检测,该函数可以检测文件或目录是否存在! Remarks ...

  2. PathFileExists用法--使用#include shlwapi.h

    转载于:http://www.cnblogs.com/joeblackzqq/archive/2010/11/09/1872309.html BOOL PathFileExists(LPCTSTR p ...

  3. MFC查找指定文件是否存在,PathFileExists 函数

    MFC判断目录下是否包含指定文件. 含文件名. 1.包含库 #include <shlwapi.h>#pragma comment(lib,"Shlwapi.lib") ...

  4. c语言中external,static关键字用法

    static用法: 在C中,static主要定义全局静态变量.定义局部静态变量.定义静态函数. 1.定义全局静态变量:在全局变量前面加上关键字static,该全局变量变成了全局静态变量.全局静态变量有 ...

  5. Pandas_transform的用法

    先来看一个实例问题. 如下销售数据中展现了三笔订单,每笔订单买了多种商品,求每种商品销售额占该笔订单总金额的比例.例如第一条数据的最终结果为:235.83 / (235.83+232.32+107.9 ...

  6. Python中yield和yield from的用法

    yield 后面接的是 future 对象 调用方 委托生成器 yield from 直接给出循环后的结果 yield from 委托者和子生成器直接通信 yield from 直接处理stopIte ...

  7. pytorch学习 中 torch.squeeze() 和torch.unsqueeze()的用法

    squeeze的用法主要就是对数据的维度进行压缩或者解压. 先看torch.squeeze() 这个函数主要对数据的维度进行压缩,去掉维数为1的的维度,比如是一行或者一列这种,一个一行三列(1,3)的 ...

  8. python yield 和 yield from用法总结

    #例1. 简单输出斐波那契數列前 N 个数 #缺点:该函数可复用性较差,因为 fab 函数返回 None,其他函数无法获得该函数生成的数列 #要提高 fab 函数的可复用性,最好不要直接打印出数列,而 ...

  9. tf.nn.embedding_lookup()的用法

    函数: tf.nn.embedding_lookup( params, ids, partition_strategy='mod', name=None, validate_indices=True, ...

最新文章

  1. 在全面部署 IPV6 前,你需要了解都在这儿
  2. 竟有内鬼!北理工硕士生「复制粘贴」论文,旷视研究员最新声明
  3. 《因果学习周刊》第10期:ICLR2022中最新Causal Discovery相关论文介绍
  4. eclipse 配置java路径_Java修改eclipse中web项目的server部署路径问题
  5. Java操作XML文件 dom4j 篇【转】
  6. 对php专业的认识,对PHP要有个全面的认识
  7. Hibernate 注解配置
  8. linux重定向到文件permission denied
  9. 【PHP】伪静态 - 1. 使用正则表达式实现
  10. 目标检测发展路程(一)——Two stage
  11. 判断画布中有重复纪录
  12. 2016年度太和顾问北京高科技行业人力资本数据信息发布
  13. Python说文解字_半成品再加工
  14. file open error: [Errno 2] No such file or directory: '\xe6\xb5\x8b\xe8\xaf\x95.txt'
  15. 如何通过云解析DNS,5步帮你实现邮箱解析
  16. [py] 考拉兹猜想
  17. 程序员的“九阳神功”——设计模式
  18. Your account has been flagged. Because of that, your profile is hidden from the public. If you belie
  19. Flutter开发之——Icon图标
  20. 计算机基本防范技术教案,电脑病毒处处防 教案(华科版信息技术上册)

热门文章

  1. repo 无法连接的解决方法
  2. BI-数据智能-MateBase
  3. Unity使用Input Sytem实现手柄震动
  4. 【DL】网络搭建及训练
  5. 电脑磁盘内的PPT文档不见了,如何尽快找回?
  6. 免越狱苹果群控巽风投屏中控
  7. 使用Docker部署web项目
  8. 阿里云服务器中挖矿病毒处理方法,centos7
  9. □ 影片名:《星河战队II 》(2026)
  10. 适合视力障碍者的Linux