如何使用 Ruby 在目录中找到最近修改的文件夹? [英] How can you find the most recently modified folder in a directory using Ruby?
本文介绍了如何使用 Ruby 在目录中找到最近修改的文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在使用 Ruby 的目录中找到最近修改的文件夹(NOT A FILE)?
How can you find the most recently modified folder (NOT A FILE) in a directory using Ruby?
推荐答案
Dir.glob("a_directory/*/").max_by {|f| File.mtime(f)}
Dir.glob("a_directory/*/")
返回 a_directory
中的所有目录名称(作为字符串),max_by
返回File.mtime
返回最大(即最近)日期的目录的名称.
Dir.glob("a_directory/*/")
returns all the directory names in a_directory
(as strings) and max_by
returns the name of the directory for which File.mtime
returns the greatest (i.e. most recent) date.
更新答案以匹配更新后的问题
updated answer to match the updated question
这篇关于如何使用 Ruby 在目录中找到最近修改的文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文