开发者

Create array of files and sort by date in ruby

开发者 https://www.devze.com 2023-02-06 00:53 出处:网络
I have a开发者_StackOverflow中文版n array of filenames, is there any way to sort these files by modification date?You can use the sort_by method in conjunction with File.mtime method, which returns th

I have a开发者_StackOverflow中文版n array of filenames, is there any way to sort these files by modification date?


You can use the sort_by method in conjunction with File.mtime method, which returns the last modification time of the given file.

filenames.sort_by {|filename| File.mtime(filename) }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号