raxbg

ListDir

Feb 17th, 2012
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. void ListDir(char *dir, DIR *dp, struct dirent *ep,bool recursive, int indent){
  2.     DIR *tdp;
  3.     struct dirent *tep;
  4.     char tmpDir[256];
  5.     if (dir[strlen(dir)-1] != '/') strcat(dir,"/");
  6.     dp = opendir(dir);
  7.     if (dp != NULL){
  8.         while (ep = readdir(dp)){
  9.             strcpy(tmpDir,dir);
  10.             strcpy(tmpDir,strcat(tmpDir,ep->d_name));
  11.             for(int i=0; i<indent; i++) cout << '-';
  12.            
  13.             tdp = opendir(tmpDir);
  14.             if (tdp != NULL){
  15.                 closedir(tdp);
  16.                 if (recursive) ListDir(tmpDir,tdp,tep,recursive,indent);
  17.             }
  18.             //else ReadFile();
  19.             if(ep->d_name != "." && ep->d_name != "..")cout << ep->d_name << endl;
  20.             tmpDir[0] = '\0';//ClearStr(tmpDir);
  21.         }
  22.         closedir(dp);
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment