PathFileExists用法--使用#include <shlwapi.h>
2011-08-31 15:49
555 查看
转载于:/article/5193202.html
BOOLPathFileExists(LPCTSTRpszPath);
Determinesifafileexists.
---经检测,该函数可以检测文件或目录是否存在!
Remarks
Thisfunctionteststhevalidityofthefileandpath.Itworksonlyonthelocalfilesystemoronaremotedrivethathasbeenmountedtoadriveletter.ItwillreturnFALSEforremotefilepathsthatbeginwiththeUNCnames\\serveror\\server\share.ItwillalsoreturnFALSEifamountedremotedriveisoutofservice.
为了使用PathFileExists(),必须包含头文件"shlwapi.h",范例代码如下:
#include<windows.h> |
#include<iostream.h> |
#include<shlwapi.h> |
void
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:"
|
cout<< "Thefilerequested\""
"\"isavalidfile"
|
cout<< "Thereturnfromfunctionis:"
|
} |
else |
{ |
cout<< "Thefilerequested"
"isnotavalidfile"
|
cout<< "Thereturnfromfunctionis:"
|
} |
//Searchforthepresenceofafilewithafalseresult. |
retval=PathFileExists(lpStr2); |
if (retval==1) |
{ |
cout<< "\nThefilerequested"
"isavalidfile"
|
cout<< "Searchforthefilepathof:"
|
cout<< "Thereturnfromfunctionis:"
|
} |
else |
{ |
cout<< "\nThefilerequested\""
"\"isnotavalidfile"
|
cout<< "Thereturnfromfunctionis:"
|
} |
} |
__imp__PathFileExistsA@4
网上搜索了下,发现是因为没有添加相应的lib。添加lib的方法网上有不少,这里使用下面的方法:
这样,就可以通过编译了!
相关文章推荐
- PathFileExists用法--使用#include <shlwapi.h>
- PathFileExists用法--使用#include <shlwapi.h>
- JSP 使用<%@include%>报Duplicate local variable path 错误 解决方法
- JSP 中使用<%@include%> 报 Duplicate local variable path 错误的解决方法
- JSP中 <%@ include file="相对url"%>和path basePath
- Android Developers:使用<include/>重用布局
- android中<include />标签的用法
- <%@ include file=” ”%> 和<jsp:include page=” ” flush=”true”/> 区别
- C语言中两种方式使用#include命令,#include <>与#include ””的区别是什么?
- android的xml中<viewStub />, <requestFocus />, <merge /> and <include />的用法
- <%@ include file="" %>和<jsp:include page="" />的区别
- 使用<input type="file">实现文件上传
- #include<vector> 的用法
- <jsp:include page="xxx"> 和<%@include file="xxx">区别
- include使用“”还是<>?
- Android UI 优化 使用<include/>和 <merge />标签
- JSP引入文件的<%@ include file="FourthJsp.jsp" %>方法阐述
- android中<include />标签的用法
- <%@ include file=""%> 和<jsp:include page=""/>两者的区别
- PathFileExists用法--使用#include