linux c 获取文件的时间信息

来源:互联网 发布:ksp 原版阻力算法 编辑:程序博客网 时间:2024/06/04 08:13
/*************************************************************************    > 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));    }}

0 0
原创粉丝点击