From: brabuhr@... Date: 2009-08-08T12:23:58+09:00 Subject: Re: I want a script can do this On Fri, Aug 7, 2009 at 10:32 PM, Jacky Cheung wrote: > I want a script can do this: > a directory aa , under aa has many files. i want batch rename all files. > like this > the file name is test01 test02 test03 ... test09 test10 test11... test29.... > rename > test1 test2 test3 ....test9 test10 test29..... > > how can i write this script? One possible method to map the file names: irb(main):001:0> a = %w{ test01 test02 test03 test09 test10 test11 } => ["test01", "test02", "test03", "test09", "test10", "test11"] irb(main):002:0> b = a.map{|i| i.scan(/([^\d]+)(\d+)/).flatten } => [["test", "01"], ["test", "02"], ["test", "03"], ["test", "09"], ["test", "10"], ["test", "11"]] irb(main):003:0> c = b.map{|i| [ i[0], i[1].to_i ].join } => ["test1", "test2", "test3", "test9", "test10", "test11"]