如何在 Windows 上的 Ruby 中获取文件创建时间? [英] How do I get the file creation time in Ruby on Windows?

查看:21
本文介绍了如何在 Windows 上的 Ruby 中获取文件创建时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I get the file creation time in Ruby on Windows?

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

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

dir /tc in cmd.exe returns creation time with bunch of other stuff.

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

Is there a better way than exec'ing it and parsing?

推荐答案

显然,文件的ctime"(创建"或更改"时间)元数据属性是 系统相关 因为某些系统(例如 Windows)存储文件的时间created(它的出生日期")和其他(Posix 系统,例如 Linux)跟踪它上次更新的时间.Windows 使用 ctime 属性 作为实际创建时间,因此您可以使用Ruby 中的各种 ctime 函数.

Apparently, the "ctime" ("creation" or "change" time) metadata attribute of a file is system dependent as some systems (e.g. Windows) store the time that a file was created (its "birth date") and others (Posix systems, e.g. Linux) track the time that it was last updated. Windows uses the ctime attribute as the actual creation time, so you can use the various ctime functions in Ruby.

File 类具有名为 的静态和实例方法ctime 返回最后修改时间和 File::Stat 有一个实例方法(不同之处在于不跟踪发生的变化).

The File class has static and instance methods named ctime which return the last modified time and File::Stat has an instance method (which differs by not tracking changes as they occur).

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.

这篇关于如何在 Windows 上的 Ruby 中获取文件创建时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆