Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.04 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <dirent.h>
  3. #include <string.h>
  4. #include <sys/types.h>
  5. #include <stdlib.h>
  6. #define memory 15
  7. void listDir(char *path){
  8.     DIR *dir = opendir(path);
  9.     if(!dir){
  10.         return;
  11.     }
  12.     struct dirent *de = readdir(dir); //returns struct dirent
  13.     while(de){
  14.         if (de->d_type == DT_DIR && strcmp(de->d_name, ".") != 0 && strcmp(de->d_name, "..") != 0){
  15.             int len = strlen(path);
  16.             strcat(path, "/");
  17.             strcat(path, de->d_name);
  18.             listDir(path);
  19.             path[len] = '\0';
  20.         }
  21.         if(de->d_type == DT_REG){
  22.             int len = strlen(path);
  23.             strcat(path, "/");
  24.             strcat(path, de->d_name);
  25.             FILE *f = fopen(path, "r");
  26.             char s[255];
  27.             fgets(s, 255, f);
  28.             printf("%s", s);
  29.             path[len] = '\0';
  30.         }
  31.         de = readdir(dir);
  32.     }
  33.     closedir(dir);
  34.     return;
  35. }
  36.  
  37. int main(){
  38.     char** text;
  39.     int count;
  40.     char path[1000] = "./lab3";
  41.     listDir(path);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement