Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _XOPEN_SOURCE 500
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <errno.h>
- #include <ftw.h>
- int count(const char *pathname, const struct stat *sb, int typeflag, struct FTW *buf);
- int files, directories, symbolic_link;
- int main(int argc, char* argv[])
- {
- if(argc != 2)
- {
- printf("No catalog to show");
- return 1;
- }
- int flags = FTW_CHDIR | FTW_DEPTH | FW_PHYS;
- nftw(argv[1], count, 5, flags);
- int sum = files + directories + symbolic_link;
- printf("Wszystkich plikow in %s: %d\n", argv[1], sum);
- printf("%d plikow normalnych %d%% udzialu\n", files, 100 * files/sum);
- printf("%d katalogow %d%% udzialu\n", directories, 100 * directories/sum);
- printf("%d dowiazan symbolicznych %d%% udzialu\n", symbolic_link, 100 * symbolic_link/sum);
- return 0;
- }
- int count(const char *pathname, const struct stat *sb, int typeflag, struct FTW *buf)
- {
- printf("%d\n", typeflag);
- if(typeflag == FTW_F)
- files++;
- else if(typeflag == FTW_D)
- directories++;
- else if(typeflag == FTW_SL)
- symbolic_link++;
- else if(typeflag == FTW_DP)
- ++directories;
- else if(typeflag == FTW_SLN)
- ++symbolic_link;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement