【发布时间】:2011-06-18 01:39:59
【问题描述】:
如何获取文件的创建日期?我正在运行 Windows。
【问题讨论】:
-
在哪个操作系统下?
-
科迪,windows 我猜,win98/2000/vista 和 7 的 api 没有变化
-
@Mandrake:当 Cody 发表评论时,问题中没有说 windows。
如何获取文件的创建日期?我正在运行 Windows。
【问题讨论】:
在 Windows 上,您应该为此使用 GetFileAttributesEx 函数。
【讨论】:
ftCreationTime.dwLowDateTime 和` ftCreationTime.dwLowDateTime `,为什么发生这种情况?谢谢
对于 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。
【讨论】:
GetFileAttributesEx 在此特定用途上优于 GetFileTime,原因有以下三个: 1. 使用 GetFileTime 需要打开文件的句柄(因此必须正确管理句柄) 2 . 由于 (1),性能可能会受到影响,因为系统实际上必须查找文件而不是 MFT 位置 3。由于 (1),GetFileAttributesEx 通常需要比GetFileTime 更少的权限,并且自动要求检索文件元数据而不是文件本身所需的最低权限。
Unix 系统不存储文件创建时间。 Unix 系统do 存储上次读取文件的时间(如果为该特定文件系统打开了atime;有时为了速度而禁用它),上次修改文件的时间(@987654322 @),以及上次更改文件元数据的时间 (ctime)。
有关使用它的详细信息,请参阅stat(2) 联机帮助页。
【讨论】:
使用统计功能
见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
【讨论】:
stat。我确实看到了_stat。