枚举文件

代码
void CWhiteInputTool_VCDlg::SearchFile(CString strDir)
{
    CFileFind ff;
    CString szDir 
= strDir;

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

    szDir 
+= _T("*.*");

    BOOL res 
= ff.FindFile(szDir);
    
while(res)
    {
        res 
= ff.FindNextFile();

        
if(ff.IsDirectory() && !ff.IsDots())//目录是文件夹
        {
            
//如果是一个子目录,用递归继续往深一层找

            CString strPath 
= ff.GetFilePath(); 
            
//得到路径,做为递归调用的开始
            CString strTitle = ff.GetFileName();
            
//得到目录名
            
            SOFTPATH softpath;
            softpath.strFileName
=strTitle;
            softpath.strFilePath
=strPath;
            m_list_softpath.push_back(softpath);


            SearchFile(strPath);
//递归调用
        }
        
else if(!ff.IsDirectory() && !ff.IsDots())//到达最低层的文件
        {
            CString strPath;
            CString strTitle;
            strPath 
= ff.GetFilePath();
            strTitle 
= ff.GetFileName();
            SOFTPATH softpath;
            softpath.strFileName
=strTitle;
            softpath.strFilePath
=strPath;
            m_list_softpath.push_back(softpath);;
        }
    }
    ff.Close();
//关闭
}

 

posted @ 2010-04-15 10:36  独奏者  阅读(461)  评论(0编辑  收藏  举报