Over a million developers have joined DZone.

Get The Last Modified File In Any Given Directory

·
Gives you the last modified file in any given directory.
Returns nil if no files are found.

	def get_last_modified(dir)
		files = Dir.new(dir).select { |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 File.open(files.first, "r")
	end
Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}