PathFileExists用法--使用#include
2011-05-09 14:22
531 查看
BOOLPathFileExists(LPCTSTRpszPath);
Determinesifafileexists.
---经检测,该函数可以检测文件或目录是否存在!
Remarks
Thisfunctionteststhevalidityofthefileandpath.Itworksonlyonthelocalfilesystemoronaremotedrivethathasbeenmountedtoadriveletter.ItwillreturnFALSEforremotefilepathsthatbeginwiththeUNCnames//serveror//server/share.ItwillalsoreturnFALSEifamountedremotedriveisoutofservice.为了使用PathFileExists(),必须包含头文件"shlwapi.h",范例代码如下:
#include<windows.h> |
#include<iostream.h> |
#include<shlwapi.h> |
void main( void ) |
{ |
//Validfilepathname(fileisthere). |
char buffer_1[]= "C://TEST//file.txt" ; |
char *lpStr1; |
lpStr1=buffer_1; |
//Invalidfilepathname(fileisnotthere). |
char buffer_2[]= "C://TEST//file.doc" ; |
char *lpStr2; |
lpStr2=buffer_2; |
//Searchforthepresenceofafilewithatrueresult. |
int retval=PathFileExists(lpStr1); |
if (retval==1) |
{ |
cout<< "Searchforthefilepathof:" <<lpStr1<<endl; |
cout<< "Thefilerequested/"" <<lpStr1<< "/"isavalidfile" <<endl; |
cout<< "Thereturnfromfunctionis:" <<retval<<endl; |
} |
else |
{ |
cout<< "Thefilerequested" <<lpStr1<< "isnotavalidfile" <<endl; |
cout<< "Thereturnfromfunctionis:" <<retval<<endl; |
} |
//Searchforthepresenceofafilewithafalseresult. |
retval=PathFileExists(lpStr2); |
if (retval==1) |
{ |
cout<< "/nThefilerequested" <<lpStr2<< "isavalidfile" <<endl; |
cout<< "Searchforthefilepathof:" <<lpStr2<<endl; |
cout<< "Thereturnfromfunctionis:" <<retval<<endl; |
} |
else |
{ |
cout<< "/nThefilerequested/"" <<lpStr2<< "/"isnotavalidfile" <<endl; |
cout<< "Thereturnfromfunctionis:" <<retval<<endl; |
} |
} |
网上搜索了下,发现是因为没有添加相应的lib。添加lib的方法网上有不少,这里使用下面的方法:
这样,就可以通过编译了!
相关文章推荐
- PathFileExists用法--使用#include <shlwapi.h>
- PathFileExists用法--使用#include <shlwapi.h>
- PathFileExists用法--使用#include <shlwapi.h>
- fileExistsAtPath: isDirectory:用法
- 使用PathFileExistss 要包含头文件shlwapi.h
- 如何使用PathFileExists
- vc6.0使用PathFileExists(...)函数的时候链接错误的解决办法
- PathFileExists()函数使用连接错误解决办法
- python中os.path.dirname(__file__)的使用
- PHP中file_exists使用中遇到的问题小结
- oracle关键字exists的使用研究(只研究用法)
- 解决使用tomcat7-maven-plugin插件时 “Application already exists at path”的问题
- 关于C# 5.0 CallerMemberName CallerFilePath CallerLineNumber 在.NET4中的使用介绍方法
- API函数PathFileExists()
- Git使用之(pathspec master did not match any file(s) known to git)
- DAY86_os.path.exists(file_path)
- 检查某目录或是文件是否存在 file_exists( ABSPATH . 'wp-config.php')
- python中关于os.path.file的详细用法
- (六)Net Core项目使用Controller之一 c# log4net 不输出日志 .NET Standard库引用导致的FileNotFoundException探究 获取json串里的某个属性值 common.js 如何调用common.js js 筛选数据 Join 具体用法
- python中os.path.dirname(__file__)的使用