user588877
user588877

Reputation:

How can I determine a file's creation date in Windows?

How can I get the date of when a file was created? I am running Windows.

Upvotes: 5

Views: 18607

Answers (4)

Remo.D
Remo.D

Reputation: 16512

For C, it depends on which operating system you are coding for. Files are a system dependent concept.

If you're system has it, you can go with the stat() (and friends) function: http://pubs.opengroup.org/onlinepubs/009695399/functions/stat.html.

On Windows you may use the GetFileTime() function: http://msdn.microsoft.com/en-us/library/ms724320%28v=vs.85%29.aspx.

Upvotes: 3

Billy ONeal
Billy ONeal

Reputation: 106530

On Windows, you should use the GetFileAttributesEx function for that.

Upvotes: 13

sarnold
sarnold

Reputation: 104050

Unix systems don't store the time of file creation. Unix systems do store the last time the file was read (if atime is turned on for that specific file system; sometimes it is disabled for speed), the last time the file was modified (mtime), and the last time the file's metadata changed (ctime).

See the stat(2) manpage for details on using it.

Upvotes: 2

Arsen Mkrtchyan
Arsen Mkrtchyan

Reputation: 50712

Use stat function

see here

#include <sys/stat.h>

#include <unistd.h>

#include <time.h>



struct tm* clock;               // create a time structure

struct stat attrib;         // create a file attribute structure

stat("afile.txt", &attrib);     // get the attributes of afile.txt

clock = gmtime(&(attrib.st_mtime)); // Get the last modified time and put it into the time structure

Upvotes: 1

Related Questions