您的位置:首页 > 其它

VC 判断文件是否存在

2012-11-02 21:06 183 查看
有下面几种方法:

方法一:

bool IsExistFile(LPCSTR pszFileName)
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind;

hFind = FindFirstFile(pszFileName, &FindFileData);

if (hFind == INVALID_HANDLE_VALUE)
{
return false;
}
else
{
FindClose(hFind);
return true;
}

return false;
}


方法二:

#include <shlwapi.h>
#pragma comment(lib, "Shlwapi.lib")

BOOL bRet = PathFileExists("C:\\aaa.docx");


方法三:

#include <IO.h>
if((_access( "C:\\aaa.docx", 0 )) != -1 )
{
//文件存在;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: