I am working on a C program where I need to get the last modified file time. What the program does is a function that goes through each file in the directory, and when a certain file (s) is found, it calls another function to check if the last modified times of the file are.
Inside the directory there are mylog.txt.1 , mylog.txt.2 and mylog.txt.3 etc. When I list the directory in linux with the ll command, I see that mylog.txt.1 and mylog.txt.2 were changed on May 4 and mylog.txt.3 was changed on May 3.
If the program checks each of these files, it always returns on May 3rd. Below is the code I'm using.
void getFileCreationTime(char *filePath) { struct stat attrib; stat(filePath, &attrib); char date[10]; strftime(date, 10, "%d-%m-%y", gmtime(&(attrib.st_ctime))); printf("The file %s was last modified at %s\n", filePath, date); date[0] = 0; }
I tried all the different st_ctime options, i.e. st_mtime and st_atime , but they all return on May 3rd.
Thanks for any help you can provide.
c linux timestamp
Boardy
source share