Getting file modification time on UNIX using utime in C

前端 未结 2 1637
抹茶落季
抹茶落季 2021-01-11 13:49

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()<

相关标签:
2条回答
  • 2021-01-11 14:49

    You can use the stat system call to get the last access and modification times.

    0 讨论(0)
  • 2021-01-11 14:53

    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;
    }
    
    0 讨论(0)
提交回复
热议问题