有下面几种方法:
方法一:
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 )
{
//文件存在;
}