Clement Ow wrote:

> 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?



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
-- 
Posted via http://www.ruby-forum.com/.