You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Windows系统的Qt中获取文件夹的创建时间?

Windows下用Qt简便获取文件夹创建时间

其实Qt的QFileInfo类在Windows平台是支持获取文件夹创建时间的,只是文档没特意针对文件夹强调这一点,而且完全不用碰Windows API,对初学者很友好:

  • 直接使用QFileInfo的birthTime()方法,它在Windows上会返回文件夹的创建时间,返回值正好是你需要的QDateTime类型。
  • 简单示例代码:
#include <QFileInfo>
#include <QDateTime>
#include <QDebug>

int main() {
    QFileInfo dirInfo("C:/目标文件夹路径");
    if (dirInfo.exists()) {
        QDateTime createTime = dirInfo.birthTime();
        qDebug() << "创建时间:" << createTime.toString("yyyy-MM-dd hh:mm:ss");
    } else {
        qDebug() << "文件夹不存在";
    }
    return 0;
}
  • 如果你的Qt版本低于5.10,那就用fileTime(QFile::FileBirthTime)方法替代,写法是dirInfo.fileTime(QFile::FileBirthTime),同样能得到QDateTime类型的创建时间。

内容的提问来源于stack exchange,提问作者jw_

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 04:52:32