Hi, I have a directory full of files and want to get the newest version
of each out of the directory. The files look like below. Please tell me
if you know a way to pull out the latest version of each. Thanks
34_web1_no2_09202008.txt
34_web1_no2_09212008.txt <--want to pull out this latest version
34_web2_no3_10122008.txt
34_web2_no3_10132008.txt <--want to pull out this latest version
dir = "C:/Status2"
files = Hash.new {|h,k| h[k] = }
Dir[File.join(dir, "*.txt")].each do |f|
files[f[/^\d+_web\d+_no\d+/]] << File.join(dir, f)
end
files.each do |k,v|
puts v.sort_by! {|f| File.mtime(f)}.last
end
Cheers
robert
···
On 09.02.2009 20:46, Mmcolli00 Mom wrote:
Hi, I have a directory full of files and want to get the newest version
of each out of the directory. The files look like below. Please tell me
if you know a way to pull out the latest version of each. Thanks
34_web1_no2_09202008.txt
34_web1_no2_09212008.txt <--want to pull out this latest version
34_web2_no3_10122008.txt
34_web2_no3_10132008.txt <--want to pull out this latest version
Hi, I have a directory full of files and want to get the newest
version of each out of the directory. The files look like below.
Please tell me if you know a way to pull out the latest version of
each. Thanks
34_web1_no2_09202008.txt
34_web1_no2_09212008.txt <--want to pull out this latest version
34_web2_no3_10122008.txt
34_web2_no3_10132008.txt <--want to pull out this latest version