CFileFind myfile;
BOOL flag=myfile.FindFile("c:\\window\\h.txt);
if(flag)
MessageBox("Find the file !");
else
MessageBox("No file !");
BOOL flag=myfile.FindFile("c:\\window\\h.txt);
if(flag)
MessageBox("Find the file !");
else
MessageBox("No file !");
解决方案 »
- 我拆分了一个视图,加了个对话框。现在在对话框上添加了一个组合框控件。怎么给这个控件添加选项呢?
- 滚动条与窗口重绘
- 50分!树形控件求助
- 关于刻录一个大小动态增长的文件?
- 怎样清空CMemFile对象的内容?
- SDK程序中有无类似MFC中的TRACE宏或者afxDump的API?
- 我程序添加modem,不弹出添加硬件向导,用什么api函数呀?急!急!急!急!急!急!急!急!急!急!急!急!急!急!急!急!急!急!急
- MajorVon()进来接分
- 各位帮我看看要怎样才能得到这个单文档窗口的柄句(findwindow的用法)?
- 加快位图的显示速度
- 讨论一下,为什么要有CTTI,真的很重要吗?
- 有关MS Agent的问题。
列目录或者打开该文件,检查返回值或错误类型 这两种方法,好像速度比ydogg(灰毛兔)的方法更慢些。还有其它的方法了吗? 如没有就结帖子了。
{
CFileStatus stat;
if(CFile::GetStatus(szFileName,stat))
return TRUE;
else
return FALSE;
}
if(!file.Open(m_PathFileName, CFile::modeRead))
{
不存在;
}
else
file.Close() ;
哈哈哈,最笨的方法了!
HANDLE hFile;
CString FilePath = "c:\\windows\\h.txt"; //file pathhFile = FindFirstFile(FilePath,&fd);if (hFile !=INVALID_HANDLE_VALUE ) //file existelse //file don't exist
GetFileAttribute,失败就表示没有 OK!jeff_hunter(PandaLee) 你的思维好开阔.DWORD GetFileAttributes(
LPCTSTR lpFileName // pointer to the name of a file or directory
);
If the function succeeds, the return value contains the attributes of the specified file or directory.
If the function fails, the return value is 0xFFFFFFFF
最简单的用 ANSI 的 access, 可判断文件是否存在,是否可读,是否可写......别的办法都没这个好吧
或
OpenFile(lpFileName, NULL, OF_EXIST);
用CFile::CFile或CFile::Open的时候,如果失败,它们就抛出CFileException
,这个CFileException::m_cause就有CFileException::fileNotFound ,这才能判断。
附失败原因:
CFileException::none No error occurred.
CFileException::generic An unspecified error occurred.
CFileException::fileNotFound The file could not be located.
CFileException::badPath All or part of the path is invalid.
CFileException::tooManyOpenFiles The permitted number of open files was exceeded.
CFileException::accessDenied The file could not be accessed.
CFileException::invalidFile There was an attempt to use an invalid file handle.
CFileException::removeCurrentDir The current working directory cannot be removed.
CFileException::directoryFull There are no more directory entries.
CFileException::badSeek There was an error trying to set the file pointer.
CFileException::hardIO There was a hardware error.
CFileException::sharingViolation SHARE.EXE was not loaded, or a shared region was locked.
CFileException::lockViolation There was an attempt to lock a region that was already locked.
CFileException::diskFull The disk is full.
CFileException::endOfFile The end of file was reached.
与大家共同探讨!
平时我们做的时候,都略过了这个问题。把打不开文件等于不存在了。