Get last modified time of file in linux

后端 未结 3 973
天命终不由人
天命终不由人 2020-12-09 09:57

I am working on a C program where I need to get the last modified time of the file. What the program does is a function loops through each file within a directory and when a

3条回答
  •  醉酒成梦
    2020-12-09 10:38

    This worked fine for me:

    #include 
    #include 
    #include 
    #include 
    #include 
    
    void getFileCreationTime(char *path) {
        struct stat attr;
        stat(path, &attr);
        printf("Last modified time: %s", ctime(&attr.st_mtime));
    }
    

提交回复
热议问题