Guest User

Untitled

a guest
Nov 2nd, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <sys/stat.h>
  4. #include <sys/types.h>
  5. #include <dirent.h>
  6. #include <unistd.h>
  7.  
  8. void list_dir(char *name) {
  9.     DIR *dir;
  10.     struct dirent *dp;
  11.     struct stat statbuf;
  12.  
  13.     if ((dir = opendir(name)) == NULL) {
  14.         perror("Blad");
  15.     }
  16.     while ((dp = readdir(dir)) != NULL) {
  17.         if (stat(dp->d_name, &statbuf) == -1)
  18.             continue;
  19.  
  20.         printf("%o %s\n", statbuf.st_mode, dp->d_name);
  21.     }
  22.     closedir(dir);
  23. }
  24.  
  25. int main(int argc, char **argv) {
  26.     char bufor[100];
  27.     scanf("%s", bufor);
  28.     list_dir(bufor);
  29.     exit(0);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment