Preserving File Timestamps
[1/3] from: cybarite::sympatico::ca at: 12-May-2004 19:46
Some months ago, there was a discussion here about maintaining file timestamps when copying
files with REBOL's write %copy read %source.
Was the resolution that it can be done? If so, what achieves this?
[2/3] from: antonr:lexicon at: 13-May-2004 22:45
This can help you:
>> get-modes %"" 'file-modes
== [creation-date access-date modification-date owner-write archived hidden
system]
>> write %afile "hi"
>> get-modes %afile get-modes %"" 'file-modes
== [creation-date: 13-May-2004/22:42:32+10:00 access-date:
13-May-2004/22:43:15+10:00 modification-date: 13-May-2004/22:43:15+10:00...
>> set-modes %afile [creation-date: 12-May-2004/0:00:00+10:00]
>> get-modes %afile get-modes %"" 'file-modes
== [creation-date: 12-May-2004/0:00+10:00 access-date:
13-May-2004/22:44:26+10:00 modification-date: 13-May-2004/22:43:15+10:00
own...
>> get-modes %afile [creation-date]
== [creation-date: 12-May-2004/0:00+10:00]
Anton.
[3/3] from: greggirwin:mindspring at: 13-May-2004 10:32
C> Some months ago, there was a discussion here about maintaining file
C> timestamps when copying files with REBOL's write %copy read %source.
C> Was the resolution that it can be done? If so, what achieves this?
Below are a couple attribute related functions I wrote a long time
ago.
-- Gregg
(watch for wrap)
touch: func [
{Set the modification timestamp of the file.}
files [file! block!] "The file, or files, you want to stamp"
/with "Use a specified time rather than the current time."
time [date!] "The date and time to stamp them with"
/local rd-only
][
if not with [time: now]
; We have to turn off the read-only attribute if it's on.
foreach item compose [(files)] [
rd-only: not get-modes item 'owner-write
set-modes to-file item [owner-write: true modification-date: time]
if rd-only [set-modes item [owner-write: false]]
]
; Should we return the time, even though it may not match the actual
; stamp on the files due to OS differences?
;time
]
attr: func [
{Return current attributes for the file.}
file [file!]
/with {Retrieve only selected attributes.}
sel {Selected attributes to retrieve.}
/avail {Return a list of attributes available for the file.}
/copy {Copy all attributes, which are safe to copy, to f2.}
f2 [file!]
/local a
][
if with [return get-modes file sel]
if avail [return get-modes file 'file-modes]
if copy [
;set-modes f2 a: get-modes file get-modes file 'copy-modes
; Core 2.5 includes full-path, which it shouldn't
;set-modes f2 a: get-modes file exclude get-modes file 'copy-modes [full-path]
set-modes f2 a: get-modes file get-modes file 'copy-modes
return a
]
get-modes file get-modes file 'file-modes
]