From: "James B. Byrne" Date: 2006-02-18T00:58:34+09:00 Subject: Re: Ruby script to Module/Class refactor William James wrote: > William James wrote: >> Regexp.new(ARGV[1]).match File.basename( p ) }.each{ |p| >> FileUtils.move( p, ARGV[2] ) } > > Please pardon previous prolixity. > > require 'fileutils' > FileUtils.move Dir[ File.join(ARGV[0], "*") ].select{ |p| > Regexp.new(ARGV[1]).match File.basename( p ) }, ARGV[2] $cat mver.rb require 'fileutils' ARGV.each {|a| puts "ARGV[#{ARGV.index(a)}]: #{a}"} FileUtils.move Dir[ File.join(ARGV[0], "*") ].select{ |p| Regexp.new(ARGV[1]).match File.basename( p ) }, ARGV[2] Does not meet specs: $ ll data/source data/target data/source: total 2268 -rw-rw-rw- 1 byrnejb byrnejb 238480 Feb 16 20:10 QPCCCMR1 -rw-rw-rw- 1 byrnejb byrnejb 785642 Feb 3 11:07 QPCCCMR2 -rw-rw-rw- 1 byrnejb byrnejb 1258930 Feb 16 20:10 QPCCCMR3 -rw-rw-rw- 1 byrnejb byrnejb 60 Feb 16 20:10 XyZQPCCCMR9aBc data/target: total 0 [byrnejb@inet05 ruby]$ ruby mver.rb data/source "QPCCCMR*" data/target ARGV[0]: data/source ARGV[1]: QPCCCMR* ARGV[2]: data/target ARGV[3]: nil [byrnejb@inet05 ruby]$ ll data/source data/target data/source: total 0 data/target: total 2268 -rw-rw-rw- 1 byrnejb byrnejb 238480 Feb 16 20:10 QPCCCMR1 -rw-rw-rw- 1 byrnejb byrnejb 785642 Feb 3 11:07 QPCCCMR2 -rw-rw-rw- 1 byrnejb byrnejb 1258930 Feb 16 20:10 QPCCCMR3 -rw-rw-rw- 1 byrnejb byrnejb 60 Feb 16 20:10 XyZQPCCCMR9aBc $ mv data/target/QPCCCMR* data/source $ ll data/source data/target data/source: total 2260 -rw-rw-rw- 1 byrnejb byrnejb 238480 Feb 16 20:10 QPCCCMR1 -rw-rw-rw- 1 byrnejb byrnejb 785642 Feb 3 11:07 QPCCCMR2 -rw-rw-rw- 1 byrnejb byrnejb 1258930 Feb 16 20:10 QPCCCMR3 data/target: total 8 -rw-rw-rw- 1 byrnejb byrnejb 60 Feb 16 20:10 XyZQPCCCMR9aBc $ ruby mver.rb data/source QPCCCMR.* data/target .ext ARGV[0]: data/source ARGV[1]: QPCCCMR.* ARGV[2]: data/target ARGV[3]: .ext [byrnejb@inet05 ruby]$ ll data/source data/target data/source: total 0 data/target: total 2268 -rw-rw-rw- 1 byrnejb byrnejb 238480 Feb 16 20:10 QPCCCMR1 -rw-rw-rw- 1 byrnejb byrnejb 785642 Feb 3 11:07 QPCCCMR2 -rw-rw-rw- 1 byrnejb byrnejb 1258930 Feb 16 20:10 QPCCCMR3 -rw-rw-rw- 1 byrnejb byrnejb 60 Feb 16 20:10 XyZQPCCCMR9aBc Globbing (not regexp, there are differences that operations personnel neither anticipate nor appreciate) does not operate as required, optional extension is not appended as required, non-positional option setting is not implemented. Does not log missing files or files moved as required. etc. While I do very much appreciate the information given in your example I can just as easily write a one line script in bash to accomplish this task if I exclude all the bells and whistles a production environment with extensive auditing requirements entails. But that is not what I am trying to accomplish. I am finding my way from procedurally based design into OOd using this embelished script as a baseline for mapping a new approach to one I am intimately familiar. Regards, Jim -- Posted via http://www.ruby-forum.com/.