Questions about copying using FileUtils

Peter Bailey wrote last Thursday, April 20, 2006 10:42 PM:

# As a related question, do all iterators, like my "each"
# below, require an "end?"

maybe we ask first "what is a block?" :slight_smile:

# Dir.chdir("c:/scripts/ruby/temp")
# require 'fileutils'
# include FileUtils::Verbose
# psfiles = Dir.glob('*.ps')
# psfiles.collect!{ |psfile| File.basename(psfile, '.ps') }
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lose this line. you do not really need it :wink:

# psfiles.each do |psfile|
# puts psfile
# FileUtils.cp("psfile", psfile + ".pageinfo")
                   ^^^^^^^^^
lose the quotes :wink:
thus, your copy will look like sample.ps.pageinfo. I prefer this one so i can trace where my backups/copy came from originally (and it resolves duplicate basenames, too)

# end

kind regards -botp