Advertisement
Guest User

Untitled

a guest
Oct 21st, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <iostream>
  4. #include <string.h>
  5. #include <dirent.h>
  6. #include <sys/stat.h>
  7. int main(int argc, char *argv[])
  8. {
  9. char PathName [256] = "/home/ubermarginal/proces";
  10. pid_t id;
  11. DIR *dir;
  12. dirent *dirName;
  13. struct stat bufStat;
  14. dir = opendir(PathName);
  15. char PathNamebuf[256]="";
  16. while ( (dirName = readdir(dir) )!=NULL )
  17. {
  18. strcpy(PathNamebuf,PathName);
  19. strcat(PathNamebuf,"/");
  20. strcat(PathNamebuf,dirName->d_name);
  21. int statError = stat(PathNamebuf,&bufStat);
  22. if (statError == 0)
  23. {
  24. if ( (S_ISDIR(bufStat.st_mode)!=0) && ((strcmp(dirName->d_name,".") ) &&(strcmp(dirName->d_name,"..") ) ) )
  25. {
  26. //std::cout << PathNamebuf << std::endl;
  27. id = fork();
  28. switch (id) {
  29. case -1:
  30. std::cout << "Error" << std::endl;
  31. break;
  32. case 0:
  33. closedir(dir);
  34. strcpy(PathName,PathNamebuf);
  35. std::cout << PathName << std::endl;
  36. dir = opendir(PathNamebuf);
  37. break;
  38.  
  39. default:
  40. break;
  41. }
  42. }
  43. }
  44. }
  45. closedir(dir);
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement