List file modification times
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <sys/types.h> | |
#include <dirent.h> | |
#include <unistd.h> | |
#include <errno.h> | |
#include <stdlib.h> | |
#include <time.h> | |
#include <sys/stat.h> | |
int main() | |
{ | |
printf("Hello, World! Test\n"); | |
char cwd[1024]; | |
char fullpath[1024]; | |
struct stat attr; | |
if (getcwd(cwd, sizeof(cwd)) != NULL){ | |
fprintf(stdout, "Current working dir: %s\n", cwd); | |
DIR *dir; | |
struct dirent *ent; | |
time_t seconds; | |
if ((dir = opendir (cwd)) != NULL) { | |
fprintf(stdout, "Files in the dir:\n"); | |
/* print all the files and directories within directory */ | |
while ((ent = readdir (dir)) != NULL) { | |
strcpy(fullpath,cwd); | |
strcat(fullpath, "/"); | |
strcat(fullpath,ent->d_name); | |
stat(fullpath, &attr); | |
seconds = time(&attr.st_mtime); | |
printf ("File: %s , modified: %ld \n", fullpath, seconds); | |
} | |
closedir (dir); | |
} | |
else { | |
/* could not open directory */ | |
perror (""); | |
return 1; | |
} | |
} | |
else | |
perror("getcwd() error"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment