void CFileSelectDlg::FindAllFile(CString strParent,HTREEITEM m_hParent)
{
CFileFind f;
BOOL bFind = f.FindFile(strParent + "*.*");
while(bFind)
{
bFind = f.FindNextFile();
if(f.IsDots()) 
continue;
if(f.IsDirectory())
{
HTREEITEM m_hParent_a;
CString m_sFilename=f.GetFileName();
m_hParent_a=m_dir.InsertItem(m_sFilename,NULL,NULL,m_hParent);
CString m_sPath=strParent+f.GetFileName()+"\\";
FindAllFile(m_sPath,m_hParent_a);
}
   }
}

解决方案 »

  1.   

    你可以看看《Windows 高级编程》
      

  2.   

    我做过,应该在
    BOOL bFind = f.FindFile(strParent + "*.*");
    前加上SetCurrentDirectory,必须将当前目录设置为要查找的目录。
      

  3.   

    我在执行的时候,tree控件中没有显示?能告诉我错误在那里吗?
      

  4.   

    找一个有两三层的文件夹来测试,单步跟踪调试一下嘛。
    我没空给你调试!
         jmcooler<签名>
      

  5.   

    BOOL bFind = f.FindFile(strParent + "\\" + "*.*");
      

  6.   

    看我的拷贝目录代码:
    BOOL CopyDirectory(CString sourcedir, CString destdirroot)
    {
    struct _finddata_t info;
    long hFile;
    long hfirstFile;
    char tmpdrive[10],tmppath[255],tmpfilename[255],tmpext[255]; CString finddir=sourcedir+CString("\\*");
    if( (hFile = _findfirst( (const char*)finddir, &info )) == -1L )
    {
    AfxMessageBox( "No any file in current directory!" );
    return FALSE;
    }
    hfirstFile=hFile; //Check if dest directory existed
    if(_access(destdirroot, 00)==-1)
    {
    if(!CreateDirectory(destdirroot,NULL))
    {
     AfxMessageBox("Create Directory"+destdirroot+"Failed!");
     return FALSE;
    }
    }
    //Sub Directory
    if (info.attrib & _A_SUBDIR)
    {
    if(CString(info.name)!=CString(".") && CString(info.name)!=CString("..") )
    CopyDirectory(sourcedir+"\\"+CString(info.name),destdirroot+CString("\\")+CString(info.name));
    }
    else //File
    {
       _splitpath(info.name,tmpdrive,tmppath,tmpfilename,tmpext);
    CopyFile(sourcedir+CString("\\")+CString(info.name),destdirroot+CString("\\")+CString(info.name));
    }
    while( _findnext( hFile, &info ) == 0 )

    //Sub Directory
    if (info.attrib & _A_SUBDIR)
    {
    if(CString(info.name)!=CString(".") && CString(info.name)!=CString("..") )
    CopyDirectory(sourcedir+"\\"+CString(info.name),destdirroot+CString("\\")+CString(info.name));
    }
    else
    {
    _splitpath(info.name,tmpdrive,tmppath,tmpfilename,tmpext);
    CopyFile(sourcedir+CString("\\")+CString(info.name),destdirroot+CString("\\")+CString(info.name));
    }
    }
    _findclose(hfirstFile);
    return TRUE;
    }
      

  7.   

    巨简单
    void Recurse(LPCTSTR pstr)
    {
    CFileFind finder;
    BOOL bWorking=finder.FindFile(pstr);
    while(bWorking)
    {
    bWorking=finder.FindNextFile();
    if(finder.IsDots()) //略过.,..文件
    continue;
    if(finder.IsDirectory()) //如果是目录文件,递归查找
    {
    CString str_d=finder.GetFilePath();
    //这句必须有,GetFilePath()得到的是类似C:\test\hello的目录名
    //如果要查找它下面的文件必须用C:\test\hello\*来递归
    //*代表当前目录下的所有目录和文件
    str_d+="\\*";
    Recurse(str_d);
    continue;
    }
    if(finder.IsReadOnly())
    {
    SetFileAttributes(finder.GetFilePath(),FILE_ATTRIBUTE_ARCHIVE);
    }
    }
    finder.Close();
    }
      

  8.   

    看我的取目录大小代码DWORD GetFolderSize(CString strDir, int &nDirCount, int &nFileCount)
    {
    if(strDir == "")
    return 0; DWORD nSize = 0; CString strDirTmp = strDir;
    if(strDirTmp.Right(1) != "\\")
    strDirTmp = strDirTmp + "\\"; CFileFind cff;
    BOOL bFind = cff.FindFile(strDirTmp + "*.*");
    while(bFind)
    {
    bFind = cff.FindNextFile();
    if(cff.IsDots())
    continue; if(cff.IsDirectory())
    {
    CString strSubDir = cff.GetFilePath();
    if(strDirTmp.Find(strSubDir)== 0)
    continue;
    nSize += GetFolderSize(strSubDir, nDirCount, nFileCount);
    nDirCount ++;
    }
    else
    {
    //是文件
    nSize += cff.GetLength()/1024;
    nFileCount ++;
    }
    } cff.Close();
    return nSize;
    }