From: "Jesús Gabriel y Galán" Date: 2008-04-23T17:16:32+09:00 Subject: Re: Extract date from filenames using regex On Wed, Apr 23, 2008 at 10:01 AM, 7stud -- wrote: > > Clement Ow wrote: > > //sins00114178/mad/Singapore/CubeMorningLDN/HKD_CUBE_risk > > report_16042008.dat size: 77 KB > > c:/ruby/lib/ruby/1.8/date.rb:1536:in `new_by_frags': invalid date > > (ArgumentError > > ) > > from c:/ruby/lib/ruby/1.8/date.rb:1583:in `parse' > > from testing.conf.rb:166:in `delFiles' > > from testing.conf.rb:163:in `glob' > > from testing.conf.rb:163:in `delFiles' > > from testing.conf.rb:162:in `each' > > from testing.conf.rb:162:in `delFiles' > > from testing.conf.rb:204 > > > > Is there anything wrong with mycode that prevents deleting all the files > > that I want? > > > > require 'date' > > str = 'sins00114178' > pattern = /(\d\d)(\d\d)(\d\d\d\d)/ > > match_obj = pattern.match(str) > puts match_obj[1] > > file_date = DateTime.parse(match_obj[1]) > > --output:-- > 00 > /usr/lib/ruby/1.8/date.rb:1214:in `new_with_hash': invalid date > (ArgumentError) > from /usr/lib/ruby/1.8/date.rb:1258:in `parse' > from r1test.rb:9 You are right, I overlooked the fact that he had added more parens in the regexp, so he was passing only two digits to DateTime.parse. Anyway the changes I proposed should work for him. Jesus.