获取文件的修改时间在UNIX上使用C中UTIME [英] Getting file modification time on UNIX using utime in C

查看:255
本文介绍了获取文件的修改时间在UNIX上使用C中UTIME的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人告诉我,一个教授,你可以使用 utime.h 获取文件的最后修改时间。然而,该男子似乎页举了 UTIME()只设置这个值。我该如何查找最后一次文件是用C改为UNIX系统上?

I have been told by a professor that you can get a file's last modification time by using utime.h. However, the man page seem to cite that utime() only sets this value. How can I look up the last time a file was changed in C on a UNIX system?

推荐答案

这返回文件的的mtime 的,最后的数据修改的时间。注意,的Unix也有一个概念的的ctime 的, 最后状态改变的时间(见的ctime,的atime,修改时间)。

This returns the file's mtime, the "time of last data modification". Note that Unix also has a concept ctime, the "time of last status change" (see also ctime, atime, mtime).

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

time_t get_mtime(const char *path)
{
    struct stat statbuf;
    if (stat(path, &statbuf) == -1) {
        perror(path);
        exit(1);
    }
    return statbuf.st_mtime;
}

这篇关于获取文件的修改时间在UNIX上使用C中UTIME的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆