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
| #include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
void aff(char *file, struct stat buf)
{
struct stat sts;
struct dirent *dirent;
printf(" %s\n", file);
printf(" %lu", sts.st_size);
return;
}
void read_folder(DIR *dir)
{
struct dirent *d;
struct stat buf;
struct stat sts;
while (d = readdir(dir))
{
aff(d->d_name, buf);
}
}
int main(int argc, char **argv)
{
DIR *dir;
if (argc != 2)
{
printf("ERROR", argv[0]);
return(-1);
}
if ((dir = opendir(argv[1])) == NULL)
{
printf("ERROR");
return(-1);
}
read_folder(dir);
closedir(dir);
} |
Partager