就是我想把一个目录下所有子目录和文件的信息保存到一个文本文件中。

解决方案 »

  1.   

    CFileFind类的FindFile()和FindNextFile()
      

  2.   

    给你一个例子,找某一目录下的所有Access数据库文件(*.mdb)
    sFolderPath :指定的目录
    CString FileName[200] ;
    HANDLE hFile;    CString tempStr;
        tempStr=sFolderPath+"\\*.mdb";    WIN32_FIND_DATA FindFileData;
        
        hFile=::FindFirstFile(tempStr,&FindFileData);    BOOL blnExact=true;
        if (hFile==INVALID_HANDLE_VALUE)
        {
                AfxMessageBox("Don't find the mdb file!");
                return;
        }    int i=0;
        FileCount=0;
        while(blnExact)
        {
                FileName[i]=FindFileData.cFileName;
                FileCount++;
                i++;
                blnExact=::FindNextFile( hFile,&FindFileData);
        }    ::FindClose(hFile);
      

  3.   

    BOOL GetFolderAndFile(CString szFolder)
    { CFileFind finder;
    CString szSearch="";
    szSearch.Format("%s\\*.*", szFolder);
    BOOL bFind=finder.FindFile(szSearch);
    if(!bFind)return FALSE;
    CString szPath="";
    while(bFind){
    bFind=finder.FindNextFile();
    if(finder.IsDots())continue;
    szPath=finder.GetFilePath();
    if(finder.IsDirectory()){
                               cout<<"find a Folder:"<<szPath<<endl;
    GetFolderAndFile(szPath);
    continue;
    }
                      else 
                      {
                           cout<<"Find a File:"<<szPath<<end;
                           //取文件属性
                           ...
                      }

    nSize+=finder.GetLength();
    } finder.Close();
    return TRUE;
    }