Guest User

Untitled

a guest
Jun 23rd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. int traverse(char path[]){
  2.  
  3. char * pathcopy = malloc(sizeof(char)*128);
  4. strcpy(pathcopy, path);
  5. struct stat * buf = malloc(sizeof(struct stat));
  6. DIR *dir = opendir(path);
  7. struct dirent *_dirent;
  8.  
  9. while((_dirent = readdir(dir)) != NULL){
  10. strcpy(pathcopy, path);
  11. if(!strcmp(_dirent->d_name, ".") || !strcmp(_dirent->d_name, "..")){
  12. continue;
  13. }
  14. strcAT(pathcopy, "/");
  15. strcAT(pathcopy, _dirent->d_name);
  16. if(stat(pathcopy, buf) != 0){
  17. printf("stat returned an error in traverse");
  18. // NEED A CONTINUE HERE!
  19. }
  20. if(S_ISDIR(buf->st_mode)){
  21. traverse(pathcopy);
  22. }
  23.  
  24. printf("%s\n", _dirent->d_name);
  25. }
  26.  
  27. return 0;
  28. }
Add Comment
Please, Sign In to add comment