文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>C++递归之获取文件列表

C++递归之获取文件列表

时间:2011-05-29  来源:Eslizn

  递归是个好东西啊

#include <iostream> 
#include <windows.h>
#include <string>
using namespace std;
char* str_add(char* a, char* b);
void EchoFiles(TCHAR* path,TCHAR* type);

int main() 
{
 TCHAR* path;
 TCHAR* type = "*";
 char input[MAX_PATH];
 cout << " Input Path:";
 cin >> input;
 cout << "\n You Input Path Is:" << input << endl;
 path = str_add(input,"");
 //cout << path << endl;
 EchoFiles(path,type);
 return 0;
}

char* str_add(char* a, char* b)
{
      char* t = new char[strlen(a) + strlen(b) + 1];
      static char* tmp;
      sprintf(t,"%s%s",a,b);
      tmp = t;
      return tmp;
}

void EchoFiles(TCHAR* path,TCHAR* type)
{
     
     WIN32_FIND_DATA  fInfo;
     HANDLE hFile;

     hFile = FindFirstFile(str_add(path,type),&fInfo);
     
     while(hFile != INVALID_HANDLE_VALUE)
     {
                 
        if(fInfo.dwFileAttributes == 16)
        {
           if(strcmp(fInfo.cFileName,".") != 0 && strcmp(fInfo.cFileName,"..") != 0)
           {
               TCHAR* tp = str_add(path,fInfo.cFileName);
               EchoFiles(str_add(tp,"\\"),type);
           }                
        }
        else
        {
           cout << str_add(path,fInfo.cFileName) << endl;
        }
        
        if(FindNextFile(hFile,&fInfo) == 0)
        {
           break;                                 
        }
     }
     FindClose(hFile);
     
}

GetFileLits.zip

相关阅读 更多 +
排行榜 更多 +
翌日波奇狗的历险记手机版下载

翌日波奇狗的历险记手机版下载

休闲益智 下载
怪兽远征安卓版下载

怪兽远征安卓版下载

角色扮演 下载
谷歌卫星地图免费版下载

谷歌卫星地图免费版下载

生活实用 下载