From: Clement Ow Date: 2008-04-23T16:14:59+09:00 Subject: Re: Extract date from filenames using regex Daniel Finnie wrote: > Hi, > > You can use File.mtime(file_name) which will return a Time object. > > You can also match with /\d+/ (one or more digits): >>> ("sdf555sadfsdfg")[/\d+/] > => "555" > > But watch out!: >>> ("sdf555sadfs5867dfg")[/\d+/] > => "555" > > For a nice, object-oriented approach to file manipulation in Ruby, you > might want to check out Pathname in the standard library: > http://www.ruby-doc.org/stdlib/libdoc/pathname/rdoc/index.html > > Dan > > On Tue, Apr 22, 2008 at 11:48 PM, Clement Ow Thanks Daniel for your input. I tried using /\d+/ but it'll extract files that have even 2 numbers to i decided to use /(\d\d)(\d\d)(\d\d\d\d)/ instead. It enabled me to run the command on certain files but not all files and the following error occured: Files/Folders deleted: //sins00114178/mad/Singapore/CubeMorningLDN/HKD_CUBE_risk report_09042008.dat size: 74 KB Files/Folders deleted: //sins00114178/mad/Singapore/CubeMorningLDN/HKD_CUBE_risk report_10042008.dat size: 81 KB Files/Folders deleted: //sins00114178/mad/Singapore/CubeMorningLDN/HKD_CUBE_risk report_11042008.dat size: 80 KB Files/Folders deleted: //sins00114178/mad/Singapore/CubeMorningLDN/HKD_CUBE_risk report_14042008.dat size: 79 KB Files/Folders deleted: //sins00114178/mad/Singapore/CubeMorningLDN/HKD_CUBE_risk report_15042008.dat size: 77 KB Files/Folders deleted: //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? -- Posted via http://www.ruby-forum.com/.