7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

特定のディレクトリの一番最近更新されたファイルを取得する

7
Posted at

『最近』という言葉は「最も近い」はずなのに、「最近」だけだと latest の意味にならない気がしたので『一番最近』にしておきました。日本語めんどくさい。

Dir.glob("*").max_by{|f| File.mtime(f) }

max_by は使いドコロが多そうですね。

参考

idioms - Ruby: Finding most recently modified file - Stack Overflow
http://stackoverflow.com/questions/4823507/ruby-finding-most-recently-modified-file

7
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?