Operation on directory


/ Published in: C
Save to your folder(s)

This simple code return the name of files


Copy this code and paste it in your HTML
  1. #include <stdio.h>
  2. #include <dirent.h>
  3. #include <sys/types.h>
  4. #include <unistd.h>
  5. #include <sys/stat.h>
  6. #include <time.h>
  7. //coded by cobra90nj
  8. int main(int argc, char **argv) {
  9.  
  10. struct dirent *drs;
  11. struct stat buf;
  12.  
  13. DIR *dir;
  14.  
  15. if (argc == 1) {
  16. dir = opendir(".");
  17. }
  18. else {
  19. dir = opendir(argv[1]);
  20. }
  21.  
  22. while ((drs = readdir(dir)) != NULL) {
  23. stat(drs->d_name, &buf);
  24. printf("\033[0;20;31m Nome File: %s\n Ultima modifica: %s\n Dimensione file: %d B \n", drs->d_name, ctime(&(buf.st_mtime)), buf.st_size);
  25. }
  26.  
  27. closedir(dir);
  28.  
  29. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.