前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >PathFileExists用法--使用#include

PathFileExists用法--使用#include

作者头像
全栈程序员站长
发布2022-09-14 10:18:56
7590
发布2022-09-14 10:18:56
举报
文章被收录于专栏:全栈程序员必看

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

代码语言:javascript
复制
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”,范例代码如下:

view source print ?

#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
PathFileExists用法--使用#include

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

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

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年7月1,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Remarks
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档