显然,文件的“ctime”(“创建”或“更改”时间)元数据属性是
system dependent
由于某些系统(例如Windows)存储文件创建的时间(“出生日期”),而其他系统(POSIX系统,例如Linux)跟踪文件上次更新的时间。Windows使用ctime属性
as the actual creation time
,这样您就可以使用
ctime
Ruby中的函数。
这个
File
类具有名为的静态方法和实例方法
CTIME
返回上次修改的时间和
File::Stat
有一个实例方法(其不同之处在于不跟踪发生的更改)。
File.ctime("foo.txt") # => Sun Oct 24 10:16:47 -0700 2010 (Time)
f = File.new("foo.txt")
f.ctime # => Will change if the file is replaced (deleted then created).
fs = File::Stat.new("foo.txt")
fs.ctime # => Will never change, regardless of any action on the file.