Advertisement
Guest User

Untitled

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