Copy File but keep Old Modified Date

December 10, 2009 at 01:09:23
Specs: Linux i686
Hey Does anyone know the code to keep an old files modified date while copying it in C?

Currently i have:
char timeStr1 [ 100 ] = "";
char timeStr2 [ 100 ] = "";
struct utimbuf new_times;

utime(argv[2], &new_times);
new_times.modtime = argv[1])

The problem im having here is conversion. is there another way i can go around doing this?

In the Terminal i know you write: cp -p <source> <Destination>


See More: Copy File but keep Old Modified Date

Report •

December 10, 2009 at 02:05:58
Since GNU is Open Source, you can have a look at the source code that implements the cp command. You'll find it on, if you do a search.

Report •

December 10, 2009 at 02:20:47
I can Copy a file fine, its just editing the modified field is the tricky part.

I can read the modified attribute of a file and print it on the terminal. I just and change it using C code :(

For Example
I copy File1 to File2
I cant keep the same modified attribute from File 1 to File2

File1 = Last Modified Mon 07 Dec 2009 10:27:00 AM GMT

File2 = Last Modified Thu 10 Dec 2009 09:39:43 AM GMT

Report •

December 10, 2009 at 02:49:34
Yes I understood what you meant. Looking at the source code for cp should show you exactly how cp achieves the preservation of the modified dates, and then you can do something similar in your own program.

Report •

Related Solutions

Ask Question