Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <sys/stat.h>
  3. #include <dirent.h>
  4. #include <errno.h>
  5.  
  6. int main(int argc, char *argv[]) {
  7.     char *chemin = ".";
  8.     int err = 0;
  9.     struct dirent *fic = NULL;
  10.  
  11.     if (argc > 1) {
  12.         chemin = argv[1];
  13.     }
  14.     printf("Ouverture du dossier : %s", chemin);
  15.  
  16.     DIR *dir = opendir(chemin);
  17.     if (dir == NULL) {
  18.         perror("");
  19.         return -1;
  20.     }
  21.  
  22.     printf("Fichier ouvert\n");
  23.  
  24.     while ((fic = readdir(dir)) != NULL) {
  25.         char type = 'f';
  26.         if (fic->d_type == DT_DIR) {
  27.             type = 'd';
  28.         }
  29.         if (fic->d_type == DT_REG) {
  30.             type = 'f';
  31.         }
  32.         printf("%c : %s\n",type, fic->d_name);
  33.     }
  34.  
  35.     err = closedir(dir);
  36.     if (err < 0) {
  37.         printf("Error\n");
  38.         return dir;
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement