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


相关推荐

  • alsa sample rate跟踪 <1>

    alsa sample rate跟踪 <1>alsasamplerate跟踪本计划全部放在一篇中,后来发现太长。因此截取成四篇,一口气看800多行,确实够烦的!之前以为alsalib中的rateplugin之所以被调用,是因为在asound.conf中指定了硬件的samplerate,例如rate48000。但实际测试下来,发现不是这么回事。无论asound.conf中是否有rate48000,驱动中得到

    2022年10月16日
  • executescalar mysql_ExecuteScalar

    executescalar mysql_ExecuteScalar这两个答案和一点点思考使我想到了一个接近答案的东西。首先再澄清一下:该应用程序是用C#(2.0+)编写的,并使用ADO.NET与SQLServer2005进行通信。镜像设置是托管主体和镜像的两个W2k3服务器以及托管作为监视器的快速实例的第三个服务器。这样做的好处是,故障转移对于使用数据库的应用程序几乎是透明的,它将对某些连接引发错误,但从根本上讲一切都会很好地进行。是的,我们得到了奇怪的误报…

    2022年6月30日
  • Landsat8的不同波段组合说明

    Landsat8的不同波段组合说明原文地址:Landsat8的不同波段组合说明作者:ENVI-IDL中国   LandsatTM(ETM+)7个波段可以组合很多RGB方案用于不同地物的解译,Landsat8的OLI陆地成像仪包括9个波段,可以组合更多的RGB方案。   OLI包括了ETM+传感器所有的波段,为了避免大气吸收特征,OLI对波段进行了重新调整,比较大的调整是OLIBand5(0.845–0.885μm),

    2022年7月23日
  • git reset后如何返回最新版本_reset按钮无法恢复

    git reset后如何返回最新版本_reset按钮无法恢复一、问题描述在利用github实现多人合作程序开发的过程中,我们有时会出现错误提交的情况,此时我们希望能撤销提交操作,让程序回到提交前的样子,本文总结了两种解决方法:回退(reset)、反做(revert)。二、背景知识git的版本管理,及HEAD的理解使用git的每次提交,Git都会自动把它们串成一条时间线,这条时间线就是一个分支。如果没有新建分支,那么…

    2022年8月22日
  • 线程池ThreadPoolExecutor简介[通俗易懂]

    线程池ThreadPoolExecutor简介[通俗易懂]1前言线程池是并发编程中一个重要的概念和技术。大多数异步或并发执行任务都会用到线程池。线程池,正如其名,它是有一定数量的线程的池子,它会执行被提交过来的任务,执行完一个任务后不会马上结束,它们会

    2022年7月4日

发表回复

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

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