【问题标题】:Obtain file properties change time using C++ on Windows在 Windows 上使用 C++ 获取文件属性更改时间
【发布时间】:2018-07-20 05:52:01
【问题描述】:

我需要 modification timecreation timechange time 使用 cpp 在 windows 中的文件。我正在使用以下代码:

string filename = "D:\\hi.txt";
struct stat result;
if (stat(filename.c_str(), &result) == 0)
{
    int a = 10;
    auto mod_time = result.st_mtime;
    cout << "modified time is: "<<mod_time<<endl;
}

使用它我可以获得modificationcreation time。但是,我无法为该文件获取change time。我应该如何使用 cpp 获取 change time 文件?

“变化时间”的定义如下。

随着文件内容的改变和修改时间的改变 即使文件的属性发生变化,更改时间也会发生变化 访问权限。

【问题讨论】:

  • 考虑到 Windows 没有 Linux 拥有的相同权限位集,那么更改时间意味着什么?

标签: c++ windows filesystems stat


【解决方案1】:

MSDN 为文件定义了三个时间戳:创建时间、上次访问时间、上次写入时间。您要求的实际上是上次访问时间。

在您的示例中,您使用了一个 Libc 函数 stat(),它适用于所有具有 C 编译器的系统。事实上,它可能过于通用,即它不代表特定环境(在您的情况下为 MS Windows)中可用的所有功能,仅代表通用属性的一个子集。

link,您可以找到GetFileTime() WinAPI 函数的描述,该函数返回 Windows 支持的文件时间。如果您编写的应用程序不打算移植到其他平台,则最好将 WinAPI 用于系统级的事情。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-30
    • 2018-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-14
    • 1970-01-01
    相关资源
    最近更新 更多