文件查找

示例代码如下:

注意:第一次找到的是.    表示本目录, 第二次找到的是..    表示上级目录,然后才找相应的文件和文件夹,按名称排序返回

void BrowseFile(CString strFile )
{
	CFileFind ff;
	CString szDir = strFile;

	if(szDir.Right(1) != "\\")
		szDir += "\\";

	szDir += "*.*";

	BOOL res = ff.FindFile(szDir);//找image目录下的文件
	
	while(res)
	{
		res = ff.FindNextFile();
		CString strPath = ff.GetFilePath();
		if(ff.IsDirectory() && !ff.IsDots())
		{
			//如果是一个子目录,用递归继续往深一层找
			CString strPath = ff.GetFilePath();
			CString strTitle = ff.GetFileTitle();
			//put your code here
			BrowseFile(strPath);
		}
		else if(!ff.IsDirectory() && !ff.IsDots())
		{
			//显示当前访问的文件
			CString strPath;
			CString strTitle;
			strPath = ff.GetFilePath();
			//put your code here
		}
	}
	ff.Close();//关闭
}
posted @ 2010-08-13 14:02  HarryChenThu  阅读(158)  评论(0编辑  收藏  举报