如何在Windows中确定文件的创建日期?

时间:2011-01-30 10:57:45

标签: c++ c windows winapi file

如何获取文件创建日期?我正在运行Windows。

4 个答案:

答案 0 :(得分:13)

在Windows上,您应该使用GetFileAttributesEx功能。

答案 1 :(得分:3)

对于C,它取决于您编码的操作系统。文件是系统相关的概念。

如果你的系统有,你可以使用stat()(和朋友)功能:http://pubs.opengroup.org/onlinepubs/009695399/functions/stat.html

在Windows上,您可以使用GetFileTime()功能:http://msdn.microsoft.com/en-us/library/ms724320%28v=vs.85%29.aspx

答案 2 :(得分:2)

Unix系统不存储文件创建的时间。 Unix系统执行存储上次读取文件的时间(如果为该特定文件系统打开了atime;有时为速度禁用),最后一次修改文件( mtime),以及文件元数据最后一次更改(ctime)。

有关使用它的详细信息,请参阅stat(2)联机帮助页。

答案 3 :(得分:1)

使用统计功能

请参阅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