PathFileExists用法--使用#include <shlwapi.h>
来源:互联网 发布:ubuntu caffe python 编辑:程序博客网 时间:2024/06/05 10:16
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的方法网上有不少,这里使用下面的方法:
或者在文件头部加入这行代码: #pragma comment(lib,"shlwapi.lib")
这样,就可以通过编译了!
0 0
- PathFileExists用法--使用#include <shlwapi.h>
- PathFileExists用法--使用#include <shlwapi.h>
- PathFileExists用法--使用#include
- 检测文件是否存在----动态链接#include《shlwapi。h》
- 使用PathFileExistss 要包含头文件shlwapi.h
- 如何使用PathFileExists
- 程序声明-include.h
- 使用#include <pthread.h>
- #include "graphics.h"用法技术
- <shlwapi.h> StrCat(a1,a2);
- #include<filename.h>和#include"filename.h"用法区别
- #include <memory.h>如何使用
- Shlwapi
- shlWapi
- shlwapi.h所包含的函数
- Shlwapi.h的所有函数列表
- shlwapi.h所包含的函数
- StrCat <shlwapi.h> strcat <string.h> wcscat <string.h>
- Android 开源框架Universal-Image-Loader完全解析(二)--- 图片缓存策略详解
- centos7下安装OMSA
- 全面理解Material Design
- 周受资担任首席财务官(CFO)一职
- PullScrollView详解(三)——PullScrollView实现
- PathFileExists用法--使用#include <shlwapi.h>
- opencv访问图像像素
- 在Android中解析XML
- redis 集群
- Git使用笔记
- 把源文件夹中的文件名称写入目的文件夹指定后缀的各个文件中
- 改变单据界面参照的过滤条件
- Android 开源框架Universal-Image-Loader完全解析(三)---源代码解读
- Python实现简单的HTTP服务器