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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4842508/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 16:06:05  来源:igfitidea点击:

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

c++cwindowswinapifile

提问by Billy ONeal

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

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

采纳答案by Arsen Mkrtchyan

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

回答by Billy ONeal

On Windows, you should use the GetFileAttributesExfunction for that.

在 Windows 上,您应该为此使用GetFileAttributesEx函数。

回答by Remo.D

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

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

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

如果您的系统拥有它,您可以使用stat()(和朋友)功能: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.

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

回答by sarnold

Unix systems don't store the time of file creation. Unix systems dostore the last time the file was read (if atimeis 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).

Unix 系统不存储文件创建时间。Unix 系统确实会存储上次读取文件的时间(如果atime为该特定文件系统打开;有时为了速度而禁用)、上次修改mtime文件的时间( ) 以及上次更改文件元数据的时间 ( ctime) .

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

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