1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| while ((entry = readdir(dir)) != NULL) {
printf("Taille Totale : %ld \n", taille);
printf("Taille Totale2 : %ld \n", tailleTotale);
char path[1024];
if (entry->d_type == DT_DIR) {
snprintf(path, sizeof(path), "%s/%s", name, entry->d_name);
//snprintf(parent, sizeof(parent), "%s", entry->d_name);
//printf("%s", parent);
if ( stat( path, &file_stat ) != 0 ) {
fprintf( stderr, "Failed to stat \"%s\": %s\n",
file_path, strerror( errno ) );
}
file_size = file_stat.st_size;
if (strcmp(entry->d_name, "..") != 0 && premier == 0) {
tailleTotale += file_stat.st_size;
}
if (strcmp(entry->d_name, ".") != 0) {
premier ++;
printf("PREMIER = %d\n", premier);
}
printf("++++%ld++++1", tailleTotale);
printf("%ld\t%s\n", file_size,entry->d_name);
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
continue;
}
// printf("[%s]\n", entry->d_name);
backup = tailleTotale;
listdir(path, tailleTotale, compteur);
} else {
snprintf(path, sizeof(path), "%s/%s", name, entry->d_name);
if ( lstat( path, &file_stat ) != 0 ) {
fprintf( stderr, "Failed to stat \"%s\": %s\n",
file_path, strerror( errno ) );
}
/*if ((file_stat.st_mode & S_IFMT) == S_IFLNK) {
tailleTotale += file_stat.st_size;
}*/
if (S_ISLNK(file_stat.st_mode)) printf ("lstat says link\n");
file_size = file_stat.st_size;
tailleTotale += file_stat.st_size;
//printf("%ld file_size, %d, tailleTotale", file_size, tailleTotale);
backup = tailleTotale;
printf("%ld\t%s\n", file_size,entry->d_name);
printf("++++%ld++++2", tailleTotale);
}
printf("++++%ld+++--3", tailleTotale);
}
closedir(dir);
} |