• C++ 获取文件创建时间、修改时间、大小等属性


    简介

    获取文件创建时间、修改时间、大小等属性

    在这里插入图片描述
    在这里插入图片描述

    代码

    #include 
    #include 
    #include 
    
    void main()
    {
        std::string filename = "E:\\LiHai123.txt";
        struct _stat stat_buffer;
        int result = _stat(filename.c_str(), &stat_buffer);
    
        struct tm tmStruct;
        char timeChar[26];
    
        localtime_s(&tmStruct, &stat_buffer.st_ctime);
        strftime(timeChar, sizeof(timeChar), "%Y-%m-%d %H:%M:%S", &tmStruct);
        std::cout << "创建时间: " << timeChar << std::endl;
    
        localtime_s(&tmStruct, &stat_buffer.st_mtime);
        strftime(timeChar, sizeof(timeChar), "%Y-%m-%d %H:%M:%S", &tmStruct);
        std::cout << "修改时间: " << timeChar << std::endl;
    
        localtime_s(&tmStruct, &stat_buffer.st_atime);
        strftime(timeChar, sizeof(timeChar), "%Y-%m-%d %H:%M:%S", &tmStruct);
        std::cout << "访问时间: " << timeChar << std::endl;
       
        std::cout << "文件大小: " << stat_buffer.st_size << " 字节" <<std::endl;
    
        /*
        std::cout << "设备号: " << stat_buffer.st_dev << std::endl;
        std::cout << "索引号: " << stat_buffer.st_ino << std::endl;
        std::cout << "文件类型和访问权限标志: " << stat_buffer.st_mode << std::endl;
        std::cout << "硬链接数量: " << stat_buffer.st_nlink << std::endl;
        std::cout << "所有者的用户标识符: " << stat_buffer.st_uid << std::endl;
        std::cout << "所有者的组标识符: " << stat_buffer.st_gid << std::endl;
        */
    
        std::cin.get();
    }
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40

    输出:
    创建时间: 2023-10-10 14:41:48
    修改时间: 2023-10-10 15:12:39
    访问时间: 2023-10-10 16:59:26
    文件大小: 1892 字节

  • 相关阅读:
    (二十六)大数据实战——kafka集群之Kraft模式安装与部署
    接口文档下的渗透测试
    Linux高性能服务器编程 学习笔记 第三章 TCP协议详解
    初识C语言
    【笔试题】【day18】
    .NET并行计算
    乘积量化(Product Quantization)算法原理
    Android 逆向
    消息队列延时聚合通知的重要性
    haproxy 负载均衡
  • 原文地址:https://blog.csdn.net/WangPaiFeiXingYuan/article/details/133751684