Advertisement
artur99

Probl2 SO S.7

Apr 3rd, 2018
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <fcntl.h>
  4. #include <fcntl.h>
  5. #include <string.h>
  6. #include <dirent.h>
  7.  
  8. #define BUFF_SIZE 1024
  9.  
  10. void browseDir(char *dirname, char* searchStr){
  11.     DIR* dd;
  12.     struct dirent * de;
  13.     char newDirName[1024];
  14.  
  15.     if(!(dd = opendir(dirname))){
  16.         printf("Error reading dir: %s\n", dirname);
  17.         return;
  18.     }
  19.     while(de = readdir(dd)){
  20.         if(de->d_type == DT_DIR){
  21.             if(!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) continue;
  22.             strcpy(newDirName, dirname);
  23.             strcpy(newDirName+strlen(newDirName), de->d_name);
  24.             strcpy(newDirName+strlen(newDirName), "/");
  25.  
  26.             browseDir(newDirName, searchStr);
  27.         }else{
  28.             if(!strcmp(de->d_name, searchStr)){
  29.                 printf("Found at: %s%s\n", dirname, de->d_name);
  30.             }
  31.         }
  32.         //printf("Entryname: %s, Type: %d\n", de->d_name, de->d_type);
  33.     }
  34. }
  35.  
  36. int main(int argc, char *argv[]){
  37.     char dirname[1024] = "/home/";
  38.     browseDir(dirname, argv[1]);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement