Parcourir une arborescence avec stat en C
Résolu/Fermé
Camlel
Messages postés
1
Date d'inscription
mercredi 1 mars 2017
Statut
Membre
Dernière intervention
1 mars 2017
-
Modifié par mamiemando le 22/03/2017 à 09:41
mamiemando Messages postés 32283 Date d'inscription jeudi 12 mai 2005 Statut Modérateur Dernière intervention 17 mars 2023 - 22 mars 2017 à 09:51
mamiemando Messages postés 32283 Date d'inscription jeudi 12 mai 2005 Statut Modérateur Dernière intervention 17 mars 2023 - 22 mars 2017 à 09:51
A voir également:
- Parcourir une arborescence avec stat en C
- Parcourir une chaine de caractère c - Forum C
- Arborescence excel - Forum Excel
- Windir stat - Télécharger - Gestion de fichiers
- Parcourir une chaine de caractère php ✓ - Forum PHP
- Voir l'arborescence d'un site - Forum Webmastering
1 réponse
mamiemando
Messages postés
32283
Date d'inscription
jeudi 12 mai 2005
Statut
Modérateur
Dernière intervention
17 mars 2023
7 572
Modifié par mamiemando le 22/03/2017 à 09:54
Modifié par mamiemando le 22/03/2017 à 09:54
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