stat()

int stat(const char *pathname, struct stat *statbuf);

功能:获取文件的元数据

参数:

pathname:文件路径

statbuf:保存文件元数据的结构体

返回值:成功:0  失败:-1,设置errno

--------------------------------------------------------------------

char *ctime(const time_t *timep);

功能:根据纪元1970-1-1 00:00:00以来经历的秒数,换算成日期字符串

参数:

timep:存储秒数的地址

返回值:成功:返回日期字符串的地址

-------------------------------------------------------------------

实例:

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>

int main(int argc, char ** argv)
{
struct stat ss;
if(argc < 2)
{
printf("usage:./a.out x.txt\n");
return -1;
}
if(stat(argv[1], &ss) == -1)
{
perror("stat");
return -1;
}
printf("Last modify time:%s",ctime(&ss.st_mtime));
}

猜你喜欢

转载自www.cnblogs.com/xpylovely/p/12052843.html