Posted By

whitetiger on 11/09/06


Tagged

Shell Bash clear dir rails unix c windows linux files cli ssh sessions cls


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

copyleft


C - command


 / Published in: C++
 

  1. /*
  2.  *
  3.  * Esempio che scansiona una cartella stampando a video i file in essa
  4.  * contenuti.
  5.  */
  6.  
  7. #include <dirent.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <sys/types.h>
  11.  
  12. int main(int argc, char *argv[])
  13. {
  14. DIR *dir;
  15. struct dirent *drent;
  16.  
  17. if(argc < 2)
  18. {
  19. fprintf(stderr, "%s <directory>\n", argv[0]);
  20. return EXIT_FAILURE;
  21. }
  22.  
  23. if((dir = opendir(argv[1])) == NULL)
  24. {
  25. fprintf(stderr, "Errore opendir()\n");
  26. return EXIT_FAILURE;
  27. }
  28.  
  29. while((drent = readdir(dir)) != NULL)
  30. {
  31. fprintf(stdout, "--> %s\n", drent->d_name);
  32. }
  33.  
  34. if(closedir(dir) < 0)
  35. {
  36. fprintf(stderr, "Errore closedir()\n");
  37. return EXIT_FAILURE;
  38. }
  39. }

Report this snippet  

You need to login to post a comment.