已知目录名, 怎样列出其下文件名和子目录, 谢谢.

解决方案 »

  1.   

    void CTtDlg::OnButton1() 
    {
        ListDirAndFile("C:\\AAa\\");
    }BOOL CTtDlg::ListDirAndFile(LPCTSTR DirName)
    {
        CFileFind tempFind; 
        char tempFileFind[200] ={0};  
        sprintf(tempFileFind,"%s\\*.*",DirName);
        
        BOOL IsFinded=(BOOL)tempFind.FindFile(tempFileFind);
        
        //find first file
        while(IsFinded)
        {
            IsFinded=(BOOL)tempFind.FindNextFile();  //research the next file in recursion
            if(!tempFind.IsDots())  //if is not "." directory
            {
                char foundFileName[200];
                strcpy(foundFileName,tempFind.GetFileName().GetBuffer(200));
                if(tempFind.IsDirectory())  //if it is directory,then do recursion
                {  
                    //DeleteDirectory
                    char tempDir[200];
                    sprintf(tempDir,"%s\\%s",DirName,foundFileName); //目录名
                    ListDirAndFile(tempDir);  //递归
                                }
                else
                {  
                    //if it is file,then delete
                    char tempFileName[200];
                    sprintf(tempFileName,"%s\\%s",DirName,foundFileName);//文件名
                }
            }
        }
        tempFind.Close();
        return TRUE;
    }
      

  2.   

    google搜索查找文件的代码,照着修改就可以了
      

  3.   

    CFileFind finder;
    BOOL bWorking = finder.FindFile("C:\\*.*");
    while (bWorking)
    {
    bWorking = finder.FindNextFile();
    std::cout << (LPCTSTR) finder.GetFileName() << std::endl;
    }