如何判断文件是否存在? parameter format : e:\temp\test.txt 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 使用_access( "e:\\temp\\test.txt", 0),返回0表示存在,否则不存在。 FILE *fp = fopen( "e:\\temp\\test.txt", "r" );if( fp == NULL ) MessageBox( "e:\\temp\\test.txt 不存在!" );else fclose( fp ); CString strPath("C:\\a.txt");HANDLE hFile = NULL; hFile= CreateFile( strPath, GENERIC_ALL, FILE_SHARE_READ, NULL, OPEN_EXISTING,//判定文件是否存在 FILE_ATTRIBUTE_NORMAL, NULL); DWORD dwErr = GetLastError();if (dwErr == ERROR_FILE_NOT_FOUND){ AfxMessageBox("FILE_NOT_FOUND");}if (hFile) CloseHandle(hFile); 或者:CFileFind find;int result=find.FindFile("C:\\aaa.txt");if(result==0){ AfxMessageBox("文件不存在");}else{ AfxMessageBox("文件存在");} #include <afx.h>CFileFind objFind ;objFind.FindFile( strFileName ) ; if ((_access(path,0))==-1)//文件不存在 { } else {} 个人觉得还是用FindFile更好些,其他的方法文件可能存在只是可能被独占打开 1.PathFileExists2.打开文件,看返回信息3._access().. 如 sans(sans) 所说, 我就不多说了 更改exe图标的问题 如何限制分割条的位置??? 关于《深入浅出MFC》 请问如何在W2K下调试ISAPI 大家介绍一下代理服务器返回的错误代码有哪些,及相关含义 请教一下语音系统中的一个问题!!! com高手请进!!!!急 MCI命令怎么用?MCI控件怎么用?回答对马上给分,谢谢! MFC 导入Excel 2010的问题 CTabCtrl控件的问题 数据的转换(二进制) 谁能给俺讲讲static 和 virtual是怎么回事???
if( fp == NULL ) MessageBox( "e:\\temp\\test.txt 不存在!" );
else fclose( fp );
HANDLE hFile = NULL;
hFile= CreateFile(
strPath,
GENERIC_ALL,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,//判定文件是否存在 FILE_ATTRIBUTE_NORMAL,
NULL);
DWORD dwErr = GetLastError();
if (dwErr == ERROR_FILE_NOT_FOUND)
{
AfxMessageBox("FILE_NOT_FOUND");
}if (hFile)
CloseHandle(hFile);
CFileFind find;
int result=find.FindFile("C:\\aaa.txt");
if(result==0)
{
AfxMessageBox("文件不存在");
}
else
{
AfxMessageBox("文件存在");
}
CFileFind objFind ;
objFind.FindFile( strFileName ) ;
{
}
else
{}
2.打开文件,看返回信息
3._access()
..