gpt4 book ai didi

ruby - 如何在 Windows 上的 Ruby 中获取文件创建时间?

转载 作者:可可西里 更新时间:2023-11-01 12:46:25 29 4
gpt4 key购买 nike

如何在 Windows 上的 Ruby 中获取文件创建时间?

File.ctime 应该返回更改时间。

cmd.exe 中的

dir/tc 返回创建时间和其他一些东西。

有比执行和解析更好的方法吗?

最佳答案

显然,文件的“ctime”(“创建”或“更改”时间)元数据属性是 system dependent因为某些系统(例如 Windows)存储文件的创建时间(其“出生日期”),而其他系统(Posix 系统,例如 Linux)会跟踪上次更新的时间。 Windows 使用 ctime 属性 as the actual creation time , 因此您可以在 Ruby 中使用各种 ctime 函数。

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.

关于ruby - 如何在 Windows 上的 Ruby 中获取文件创建时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4009288/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com