How can you find the most recently modified folder in a directory using Ruby?

前端 未结 3 331
逝去的感伤
逝去的感伤 2021-01-18 20:38

How can you find the most recently modified folder (NOT A FILE) in a directory using Ruby?

3条回答
  •  北恋
    北恋 (楼主)
    2021-01-18 21:41

    Find the most recently modified directory in the current directory:

    folders = Dir["*"].delete_if{|entry| entry.include? "."}
    newest = folders[0]
    folders.each{|folder| newest = folder if File.mtime(folder) > File.mtime(newest)}
    

提交回复
热议问题