加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

如何在Windows上使用Ruby获取文件创建时间?

发布时间:2020-12-14 04:08:52 所属栏目:Windows 来源:网络整理
导读:如何在 Windows上使用 Ruby获取文件创建时间? File.ctime应该返回更改时间. cmd.exe中的dir / tc返回创建时间和其他一些东西. 有没有比执行它和解析更好的方法? 显然,文件的“ctime”(“创建”或“更改”时间)元数据属性是 system dependent,因为某些系统(
如何在 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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读