新闻  |   论坛  |   博客  |   在线研讨会
linux c 获取文件的时间信息
电子禅石 | 2022-12-23 15:05:40    阅读:7968   发布文章

/*************************************************************************

    > File Name: hello.c

    > Author: lizhu

    > Mail: 

    > Created Time: 2015年11月20日 星期五 10时30分20秒

 ************************************************************************/

 

#include <time.h>

#include <sys/types.h>

#include <sys/stat.h>

#include <stdio.h>

 

void main( void )

{

    struct stat buf;

    int result;

 

    //获得文件状态信息

 

    result =stat( "/home/lizhu/study/gg.c", &buf );

 

    //显示文件状态信息

 

   if( result != 0 )

       perror( "显示文件状态信息出错" );//并提示出错的原因,如No such file or directory(无此文件或索引)

 

    else

    {

 

                printf("文件大小: %d", buf.st_size);

        printf("文件创建时间: %s", ctime(&buf.st_ctime));

        printf("访问日期: %s", ctime(&buf.st_atime));

        printf("最后修改日期: %s", ctime(&buf.st_mtime));

 

    }

 

}


*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。

参与讨论
登录后参与讨论
属于自己的技术积累分享,成为嵌入式系统研发高手。
最近文章
签名类型
2024-04-29 16:28:59
cat 文件名
2024-04-29 15:05:34
推荐文章
最近访客