DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Get The Last Modified File In Any Given Directory

  • submit to reddit
        Gives you the last modified file in any given directory.
Returns nil if no files are found.
	def get_last_modified(dir)
		files = { |file| file!= '.' && file!='..' }
		return nil if (files.size < 1)
		files = files.collect { |file| dir+'/'+file }
		files = files.sort { |a,b| File.mtime(b)<=>File.mtime(a) }
		return, "r")