开发者

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

开发者 https://www.devze.com 2023-02-07 18:00 出处:网络
How can I开发者_运维百科 get the date of when a file was created? I am running Windows.On Windows, you should use the GetFileAttributesEx function for that.For C, it depends on which operating system

How can I开发者_运维百科 get the date of when a file was created? I am running Windows.


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


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.


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.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号