Parcourir une arborescence avec stat en C
Résolu
A voir également:
- Forf p.stat web
- Windir stat - Télécharger - Gestion de fichiers
- Comment faire une arborescence sur word - Guide
- Stat trek tso - Forum Téléchargement
- Voir arborescence site web - Forum Webmastering
- Jai besoins d'un petit renseignement concernant le payement forf ✓ - Forum Windows Phone
1 réponse
Bonjour
Il suffit de repartir de ces liens :
https://stackoverflow.com/questions/612097/how-can-i-get-the-list-of-files-in-a-directory-using-c-or-c
https://stackoverflow.com/questions/4553012/checking-if-a-file-is-a-directory-or-just-a-file
Exemple :
Bonne chance
Il suffit de repartir de ces liens :
https://stackoverflow.com/questions/612097/how-can-i-get-the-list-of-files-in-a-directory-using-c-or-c
https://stackoverflow.com/questions/4553012/checking-if-a-file-is-a-directory-or-just-a-file
Exemple :
#include <dirent.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> int list_directory(const char * dirname) { DIR *dir; struct dirent *ent; struct stat path_stat; if ((dir = opendir(dirname)) != NULL) { /* Print all the files and directories within directory */ while ((ent = readdir(dir)) != NULL) { const char * path = ent->d_name; stat(path, &path_stat); if (S_ISREG(path_stat.st_mode)) { printf("%s: regular file\n", path); } else if (S_ISDIR(path_stat.st_mode)) { printf("%s: directory\n", path); } } closedir(dir); } else { /* Could not open directory */ perror("Cannot open directory %s", dirname); return -1; } return 0 } int main() { char * dirname = "/home/mando"; list_directory(dirname); return 0; }
Bonne chance