c++ - How to copy a file but touch the timestamp on the new copy? -



c++ - How to copy a file but touch the timestamp on the new copy? -

i using ::copyfile() create re-create of file. appears original file's timestamp beingness preserved , re-create set current timestamp on copy, i.e. 'touching' it.

is there winapi way easily?

if read msdn documentation copyfile(), there comments @ bottom following:

file times semantics article should document semantics respect file creation/modification/access times.

creation time: if target file exists, its' creation time preserved, otherwise set current scheme time. lastly modification time: copied modification time of source file. lastly access time: set current scheme time.

and

mod-time not preserved modification time not guaranteed set. copyfileex seek set modification time, no error checking on it. means if setting modification time fails internally in copyfileex (e.g. access denied), latter still returns successful!

so if modification time of import scenario (it synchronization program), have explicitly phone call setfiletime() , check it's homecoming value sure.

you should utilize setfiletime() update copied file's timestamp(s) create sure set want them set to. there illustration on msdn:

changing file time current time

#include <windows.h> // setfiletocurrenttime - sets lastly write time current scheme time // homecoming value - true if successful, false otherwise // hfile - must valid file handle bool setfiletocurrenttime(handle hfile) { filetime ft; systemtime st; bool f; getsystemtime(&st); // gets current scheme time systemtimetofiletime(&st, &ft); // converts current scheme time file time format f = setfiletime(hfile, // sets last-write time of file (lpfiletime) null, // converted current scheme time (lpfiletime) null, &ft); homecoming f; }

c++ winapi visual-c++ visual-studio-2013

Comments

Popular posts from this blog

javascript - I need to update the text of a paragraph by inline edit -

javascript - THREE.js reposition vertices for RingGeometry -

assembly - What is the addressing mode for ld, add, and rjmp instructions? -