How to preserve modification & creation date?

Hi there,

I want to preserve the modification & creation date on files copied using :

set CaptureFilepath to quoted form of (POSIX path of (theFile as text)) as text
set BackupFilepath to quoted form of (POSIX path of (ParentDirinBackup as text)) as text
set complete to do shell script "cp -R -f " & CaptureFilepath & " " & BackupFilepath

Do I have to use “touch” afterwards or is there a way to tell “cp” to do it?

kind regards

EM

mmm… Tried using ‘touch’ but it doesn’t work for some reason? Does it work over a network connection? That’s what is happeing here.

set complete to do shell script "cp -f " & CaptureFilepath & " " & BackupFilepath
set complete to do shell script "touch -r " & CaptureFilepath & " " & BackupFilepath

Any ideas?

kind regards

EM

man cp:

Hi,

read the man page!

-p Cause cp to preserve the following attributes of each source file
in the copy: modification time, access time, file flags, file mode,
user ID, and group ID, as allowed by permissions. Access Control
Lists (ACLs) will also be preserved.

I guess, these bunch of coercions are not needed,
if CaptureFilepath and BackupFilepath are aliases, this is sufficient


set CaptureFilepath to quoted form of POSIX path of theFile
set BackupFilepath to quoted form of POSIX path of ParentDirinBackup
set complete to do shell script "cp -pRf " & CaptureFilepath & " " & BackupFilepath

if the variables are Finder files, use this


set CaptureFilepath to quoted form of POSIX path of (theFile as text)
set BackupFilepath to quoted form of POSIX path of (ParentDirinBackup as text)
set complete to do shell script "cp -pRf " & CaptureFilepath & " " & BackupFilepath

I missed that the first time! Either man pages trump unnecessary coercions in my mind, or I’m getting soft. :stuck_out_tongue:

:lol:

Thanks folks ! I COMPLETELY missed it in the man page — SO sorry for wasting your time :confused:

thanks again

EM