I discovered this post about using bash
How to recursively find the latest modified file in a directory? (uses bash)
however I need to write this in ruby, I have a scenario with a network folder named "active", with many many sub directories, each sub directory has child directories and the children have child directories and so on. I need to return the date of the latest modified file contained in the lvl1 directory buried somewhere in its many child directories.
---------------------------
active | lvl1 | lvl2 | lvl3
| | | lvl3
| | lvl2 |
| | lvl2 |
| | lvl2 |
| lvl1 | |
---------------------------
edit with what I have currently which works great for returning file names, but im stuck on where to store the File.mtime() for each file occurance, I need to identify which lvl1 folder needs to be archived:
def walk(start)
Dir.foreach(start) do |x|
path = File.join(start, x)
if x == "." or x == ".."
next
elsif File.directory?(path)
walk(path)
else
puts x
end
end
end
path = 'folder\\path'
walk(path)