Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int traverse(char path[]){
- char * pathcopy = malloc(sizeof(char)*128);
- strcpy(pathcopy, path);
- struct stat * buf = malloc(sizeof(struct stat));
- DIR *dir = opendir(path);
- struct dirent *_dirent;
- while((_dirent = readdir(dir)) != NULL){
- strcpy(pathcopy, path);
- if(!strcmp(_dirent->d_name, ".") || !strcmp(_dirent->d_name, "..")){
- continue;
- }
- strcAT(pathcopy, "/");
- strcAT(pathcopy, _dirent->d_name);
- if(stat(pathcopy, buf) != 0){
- printf("stat returned an error in traverse");
- // NEED A CONTINUE HERE!
- }
- if(S_ISDIR(buf->st_mode)){
- traverse(pathcopy);
- }
- printf("%s\n", _dirent->d_name);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment