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