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


相关推荐

  • Pytest(13)命令行参数–tb的使用[通俗易懂]

    Pytest(13)命令行参数–tb的使用[通俗易懂]前言pytest使用命令行执行用例的时候,有些用例执行失败的时候,屏幕上会出现一大堆的报错内容,不方便快速查看是哪些用例失败。–tb=style参数可以设置报错的时候回溯打印内容,可以设置参

    2022年7月28日
    3
  • NYOJ202 红黑树 【预购】

    NYOJ202 红黑树 【预购】

    2022年1月17日
    39
  • opengl投影矩阵变换_opengl 坐标

    opengl投影矩阵变换_opengl 坐标前言先上一个运行效果图:OverviewAcomputermonitorisa2Dsurface.A3DscenerenderedbyOpenGLmustbeprojectedontothecomputerscreenasa2Dimage.GL_PROJECTIONmatrixisusedforthisprojectiontransformation.First,ittransformsallvertex…

    2022年9月13日
    0
  • PyCharm官网无法访问的解决办法[通俗易懂]

    PyCharm官网无法访问的解决办法[通俗易懂]问题描述  最近在研究pythonweb框架,用的是以前学python的时候用的Pycharm社区版(无力吐槽)。不太好用,就想去下个企业版用用,结果出现这种情况。。。  emmm,检查了网络没问题,换了个浏览器也是无法访问,最后辗转多个论坛发现似乎是因为hosts文件的问题。模糊的记得我好像激活成功教程过这个软件修改了一下hosts文件,改回来就可以访问Pycharm官网了。解决办法  Wi…

    2022年8月26日
    2
  • 最小二乘法求回归方程的推导[通俗易懂]

    最小二乘法求回归方程的推导[通俗易懂]这里手写的最小二乘法​​​​​​​的推导过程。  

    2022年10月24日
    0
  • OpenProcessToken令牌函数用法「建议收藏」

    OpenProcessToken令牌函数用法「建议收藏」>GetCurrentProcessID得到当前进程的IDOpenProcessToken得到进程的令牌句柄LookupPrivilegeValue查询进程的权限AdjustTokenPrivileges调整令牌权限要对一个任意进程(包括系统安全进程和服务进程)进行指定了写相关的访问权的OpenProcess操作,只要当前进程具有SeDeDebug权限就可以了。要是一个用户是Admin

    2022年6月25日
    22

发表回复

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

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