file atime

file atime name ?time?

Returns a decimal string giving the time at which file name was last accessed. If time is specified, it is an access time to set for the file. The time is measured in the standard POSIX fashion as seconds from a fixed starting time (often January 1, 1970), suitable for use with clock seconds. If the file doesn't exist or its access time cannot be queried or set then an error is generated. On Windows, FAT file systems do not support access time.

Note that there does not appear to be an interface to ctime - the time the last file attribute change occured. The ctime that is returned by file attributes is not the creation time (at least not on Unix).

The value of ctime is returned by the file stat command. The ctime is not the creation time but the last time one of the values returned by file stat changed (ergo, ctime=change time?). The ctime value can't be edited directly, but editing mtime or atime will change the ctime value.

male 2007-03-15:

Hhm - ctime from the stat array is not the creation time?

The documentation of the Tcl_Stat function from the tcl C API says:

“Tcl_Stat fills the stat structure statPtr with information about the specified file. ... The stat structure includes info regarding device, inode (always 0 on Windows), ..., size, last access time, last modification time, and creation time.”

And I tested this on my system. I used "file stat" with a file on my system and "clock format $stat(ctime)" returned the creation time to be seen in the related Explorer column.

DKF: Ugh, that was a long-standing documentation bug; ctime was always the last metadata change time.

JMN: My experience matches the previous commenter. This 'last metadata change time' still doesn't seem to match the behaviour on windows for tcl 8.6 & 8.7 On windows ctime as returned from file stat seems stubbornly rooted in the past whether permissions are changed or the file is edited, or even if unix tools such as touch are used. I see very different behaviour on FreeBSD and WSL where chmod will update ctime.

Any chance this will get looked at for Tcl 9? Perhaps a new command/pkg, seeing as this has apparently been behaving very differently on different platforms for a long time.

See also