How to modify a file date and time to current date and time in C

1 Answer

0 votes
#include <stdio.h>
#include <sys/stat.h>
#include <utime.h>
#include <time.h>

int main(int argc, char **argv) 
{ 
    const char *filename = "d:\\data.txt";
    struct stat foo;
    struct utimbuf new_times;
 
    new_times.actime = foo.st_atime; 
    new_times.modtime = time(NULL);  
    if (utime(filename, &new_times) < 0) 
    {
        perror(filename);
        return 1;
    }
    return 0;
}

/*
run:

check the file date and time on your hard disk drive

*/

 



answered Jun 17, 2015 by avibootz

Related questions

1 answer 298 views
1 answer 214 views
1 answer 1,188 views
1,188 views asked Jun 19, 2015 by avibootz
1 answer 236 views
236 views asked Jun 18, 2015 by avibootz
2 answers 257 views
2 answers 251 views
251 views asked Jun 15, 2015 by avibootz
...