Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.99 KB | None | 0 0
  1. void listDirectory(char *name) {
  2.     DIR *dir;
  3.     directoryContent fileInfo;
  4.     growingArray content;
  5.     int i;
  6.  
  7.     initArray(&content,2); 
  8.    
  9.     if ((dir = opendir(name)) == NULL) {
  10.         perror("Blad");
  11.     }
  12.  
  13.     while ((fileInfo.dp = readdir(dir)) != NULL) {
  14.       if (stat(fileInfo.dp->d_name, &(fileInfo.statbuf)) == -1)
  15.             continue;
  16.  
  17.         fileInfo.userID = getpwuid(fileInfo.statbuf.st_uid);
  18.         fileInfo.userGroup = getgrgid(fileInfo.statbuf.st_gid);
  19.         getDate(fileInfo.dateLastAccess, fileInfo.statbuf, 64);
  20.         insertArray(&content,fileInfo);
  21.     }
  22.     closedir(dir);
  23.  
  24.     qsort(content.array, content.used, sizeof(directoryContent),compare);
  25.  
  26.     for(i = 0; i < content.used; i++){
  27.        polishMonth(content.array[i].dateLastAccess);
  28.          printList(content.array[i]);  
  29.     }
  30.     freeArray(&content);
  31. }
  32.  
  33. int main(int argc, char **argv) {
  34.     if(argc <= 1){
  35.         listDirectory(".");
  36.     }
  37.     else{/*Czy tam pisze Elsa ?*/
  38.         listDirectory(argv[1]);
  39.     }
  40.     exit(0);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement