top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How can I retrieve the creation date and time of a file in C/C++?

0 votes
696 views
How can I retrieve the creation date and time of a file in C/C++?
posted Jun 2, 2017 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

File creation time is not stored anywhere,
You can only retrieve one of the following:

time_t    st_atime;   /* time of last access */
time_t    st_mtime;   /* time of last modification */
time_t    st_ctime;   /* time of last status change */

You can use below program to get st_ctime.

#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
int main(int argc, char *argv[])
{
        struct stat st;
        size_t i;

        for( i=1; i<argc; i++ )
        {
                if( stat(argv[i], &st) != 0 )
                        perror(argv[i]);
                printf("%i\n", st.st_ctime);
        }

        return 0;
}
answer Jun 5, 2017 by Chirag Gangdev
Similar Questions
+2 votes

Let's say I have an exe-file (for example computer game) and need to forbid to run it until certain date or time during the day. Any 'manipulations' with file are allowed.

Could you, please, offer me a simple way of how to encode/decode such a file mostly in C or C++?

+6 votes
...