是否可以使用 Ruby 读取文件的修改日期?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10580728/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is it possible to read a file's modification date with Ruby?
提问by ryan1393402
Is it possible to read a file's modification date with Ruby? I have successfully opened a text file and captured the contents of the file with
是否可以使用 Ruby 读取文件的修改日期?我已经成功打开了一个文本文件并使用以下命令捕获了文件的内容
File.open("test.txt", "r").each do |line|"
but it would be very useful to read the modification date of the file.
但是读取文件的修改日期会非常有用。
回答by Matzi
"Returns the modification time for the named file as a Time object."
“将命名文件的修改时间作为 Time 对象返回。”
File.mtime("testfile") #=> Tue Apr 08 12:58:04 CDT 2003

