Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <dirent.h>
- #include <string.h>
- #include <unistd.h>
- #define PATH_MAX 4096
- void parcours_rep(char *path, char *end)
- {
- struct dirent *lecture;
- struct stat statbuf;
- DIR *rep;
- printf("%s\n", path);
- if (lstat(path, &statbuf)) // on saute si lstat échoue
- return;
- if (S_ISLNK(statbuf.st_mode)) // on saute les symlinks;
- return;
- if (!(rep = opendir(path)))
- return; // opendir échoue, on se contente de retourner
- *end++ = '/'; // on ajoute un / a la fin du path
- while ((lecture = readdir(rep)))//parcours des elements du repertoire
- {
- if (lecture->d_name[0] == '.')
- continue;
- strcpy(end, lecture->d_name);
- parcours_rep(path, end + strlen(lecture->d_name));
- }
- closedir(rep);
- }
- int main()
- {
- char path[4096] = "/";
- parcours_rep(path, path + strlen(path));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment