糖尿病康复,内容丰富有趣,生活中的好帮手!
糖尿病康复 > 判断文件是否存在 判断是否为文件夹

判断文件是否存在 判断是否为文件夹

时间:2024-03-13 02:12:59

相关推荐

判断文件是否存在 判断是否为文件夹

判断路径(文件或文件夹)是否存在[cpp]view plain copy print ?BOOLFileExist(CStringstrPath) { WIN32_FIND_DATAwfd; BOOLrValue=FALSE; HANDLEhFind=FindFirstFile(strPath,&wfd); if((hFind!=INVALID_HANDLE_VALUE) &&(wfd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)) { rValue=TRUE; } FindClose(hFind); returnrValue; }

判断路径是否为文件夹

[cpp]view plain copy print ?#pragmacomment(lib,"shlwapi.lib") #include<shlwapi.h> BOOLPathIsDirectory(strPath)

判断文件是否存在。

1._access函数,在io.h中。

原型:int _access(const char *filename, int amode);

参数amode(好象有5种模式)

0:检查文件是否存在

1:检查文件是否可运行

2:检查文件是否可写访问

4:检查文件是否可读访问

还有一种,由于MSDN突然坏了,暂时保留着

[cpp]view plain copy print ?if(_access(file,0)) { //文件不存在 }

2.CFile和CFileStatus类

CFile的静态函数GetStatus如果返回FALSE表示文件不存在

[cpp]view plain copy print ?CFileStatusfs; if(!CFile::GetStatus(strFileName,fs)) { //文件不存在 }

3.CFileFind类

直接使用该类的成员函数FindFile进行判断

[cpp]view plain copy print ?CFileFindff; if(!ff.FindFile(strFileName)) { //文件不存在 } ff.Close();

3.判断文件夹是否存在

[cpp]view plain copy print ?DirExists(sPath);

转自:/wangjieest/article/details/7000640

如果觉得《判断文件是否存在 判断是否为文件夹》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。