Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _XOPEN_SOURCE 500
- #include <stdio.h>
- #include <malloc.h>
- #include <stdlib.h>
- #include <dirent.h>
- #include <string.h>
- #include <sys/stat.h>
- #include <time.h>
- #include <ftw.h>
- #include <stdint.h>
- char* getType(int fileType) {
- char* type;
- switch (fileType) {
- case FTW_F:
- type = "file";
- break;
- case FTW_D:
- type = "dir";
- break;
- case FTW_SL:
- type = "slink";
- break;
- default:
- type ="error";
- break;
- }
- return type;
- }
- char* getDateFromTimestamp(time_t timestamp, struct tm* ts) {
- char* date = calloc(80, sizeof(char));
- *ts = *localtime(×tamp);
- strftime(date, 80*sizeof(char), "%a %Y-%m-%d %H:%M:%S %Z", ts);
- return date;
- }
- static int printData(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf) {
- struct tm ts;
- char* type = getType(tflag);
- char* path = realpath(fpath, NULL);
- char* aDate = getDateFromTimestamp(sb->st_atime, &ts);
- char* mDate = getDateFromTimestamp(sb->st_mtime, &ts);
- printf("%s:\n Pełna ścieżka: %s\n Rodzaj pliku: %s\n Rozmiar pliku: %ld B\n Data ostatniego dostępu: %s\n Data ostatnie modyfikacji: %s\n", fpath, path, type, sb->st_size, aDate, mDate);
- return 0;
- }
- int main(int argc, char* argv[]) {
- char* startDir = argv[1];
- char* mode = argv[2];
- char* day = argv[3];
- char* month = argv[4];
- char* year = argv[5];
- int flags = 0;
- flags |= FTW_PHYS;
- if(argc < 6) {
- printf("Podano złą liczbę argumentów\n");
- } else if(strcmp(mode, "=") && strcmp(mode, ">") && strcmp(mode, "<")) {
- printf("Wprowadzono nieprawidłowy znak porówniania\n");
- } else {
- nftw(startDir, checkData, 20, flags);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement