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”,范例代码如下:
char
buffer_1[] =
"C://TEST//file.txt"
;
char
buffer_2[] =
"C://TEST//file.doc"
;
int
retval = PathFileExists(lpStr1);
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;
cout <<
"The file requested "
<< lpStr1 <<
" is not a valid file"
<< endl;
cout <<
"The return from function is: "
<< retval << endl;
retval = PathFileExists(lpStr2);
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;
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的方法网上有不少,这里使用下面的方法:
这样,就可以通过编译了!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/158053.html 原文链接:https://javaforall.cn
【正版授权,激活自己账号】:
Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】:
官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...