Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/stat.h>
- #include <dirent.h>
- #include <errno.h>
- int main(int argc, char *argv[]) {
- char *chemin = ".";
- int err = 0;
- struct dirent *fic = NULL;
- if (argc > 1) {
- chemin = argv[1];
- }
- printf("Ouverture du dossier : %s", chemin);
- DIR *dir = opendir(chemin);
- if (dir == NULL) {
- perror("");
- return -1;
- }
- printf("Fichier ouvert\n");
- while ((fic = readdir(dir)) != NULL) {
- char type = 'f';
- if (fic->d_type == DT_DIR) {
- type = 'd';
- }
- if (fic->d_type == DT_REG) {
- type = 'f';
- }
- printf("%c : %s\n",type, fic->d_name);
- }
- err = closedir(dir);
- if (err < 0) {
- printf("Error\n");
- return dir;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement