Questions about copying using FileUtils

Hello,
Can someone please help me with the following script? It doesn't work,
and yields the message below this script. My "puts" is just for testing,
to see if it sees the files. The "puts" works fine when I don't include
the copy line just below it. I'm just copying original files to files of
the same name, with different extensions. I could as well be opening new
files of these new names, not just copying them.

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

Thanks a lot.

···

______________________________________________________________________________
Dir.chdir("c:/scripts/ruby/temp")
require 'fileutils'
include FileUtils::Verbose
psfiles = Dir.glob('*.ps')
psfiles.collect!{ |psfile| File.basename(psfile, '.ps') }
psfiles.each do |psfile|
    puts psfile
    FileUtils.cp("psfile", psfile + ".pageinfo")
end
-------------------------------------------------------------------------------
gives me this . . .
test1
c:/ruby/lib/ruby/1.8/fileutils.rb:1182:in `stat': No such file or
directory - ps
file (Errno::ENOENT)
        from c:/ruby/lib/ruby/1.8/fileutils.rb:1182:in `lstat'
        from c:/ruby/lib/ruby/1.8/fileutils.rb:1160:in `stat'
        from c:/ruby/lib/ruby/1.8/fileutils.rb:1242:in `copy_file'
        from c:/ruby/lib/ruby/1.8/fileutils.rb:459:in `copy_file'
        from c:/ruby/lib/ruby/1.8/fileutils.rb:383:in `cp'
        from c:/ruby/lib/ruby/1.8/fileutils.rb:1377:in
`fu_each_src_dest'
        from c:/ruby/lib/ruby/1.8/fileutils.rb:1393:in
`fu_each_src_dest0'
        from c:/ruby/lib/ruby/1.8/fileutils.rb:1375:in
`fu_each_src_dest'
        from c:/ruby/lib/ruby/1.8/fileutils.rb:382:in `cp'
        from c:/scripts/ruby/images/check_indexes.rb:10
        from c:/scripts/ruby/images/check_indexes.rb:8
--------------------------------------------------------------------------------

--
Posted via http://www.ruby-forum.com/.

Dir.chdir("c:/scripts/ruby/temp")
require 'fileutils'
include FileUtils::Verbose
psfiles = Dir.glob('*.ps')
psfiles.collect!{ |psfile| File.basename(psfile, '.ps') }
psfiles.each do |psfile|
    puts psfile
    FileUtils.cp("psfile", psfile + ".pageinfo")

                    ^^^^^^^^

Why do you use " here ? ruby search the file "psfile" and not the name
given in the variable `psfile'

Just write

   FileUtils.cp(psfile, psfile + ".pageinfo")

end

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

This is `do' which need an `end'

You can write
  
   1.times do |i|
      puts i
   end

or

   1.times {|i|
      puts i
   }

Guy Decoux

Peter Bailey wrote:

psfiles.each do |psfile|
    puts psfile
    FileUtils.cp("psfile", psfile + ".pageinfo")
end

psfile is a variable and should not be quoted. Use

      FileUtils.cp(psfile, psfile + ".pageinfo")

···

--
Posted via http://www.ruby-forum.com/\.

psfiles = Dir.glob('*.ps')
psfiles.collect!{ |psfile| File.basename(psfile, '.ps') }
psfiles.each do |psfile|
    puts psfile
    FileUtils.cp("psfile", psfile + ".pageinfo")

There is another problem, you have removed the suffix .ps with
File::basename, best to write it

      FileUtils.cp(psfile + ".ps", psfile + ".pageinfo")
      
Guy Decoux

ts wrote:

> Dir.chdir("c:/scripts/ruby/temp")
> require 'fileutils'
> include FileUtils::Verbose
> psfiles = Dir.glob('*.ps')
> psfiles.collect!{ |psfile| File.basename(psfile, '.ps') }
> psfiles.each do |psfile|
> puts psfile
> FileUtils.cp("psfile", psfile + ".pageinfo")
                    ^^^^^^^^

Why do you use " here ? ruby search the file "psfile" and not the name
given in the variable `psfile'

Just write

   FileUtils.cp(psfile, psfile + ".pageinfo")

> end

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

This is `do' which need an `end'

You can write

   1.times do |i|
      puts i
   end

or

   1.times {|i|
      puts i
   }

Guy Decoux

Thanks, Guy. I re-did that line, but get the same results.

FileUtils.cp(psfile, psfile + ".pageinfo")

OK. So, it's the "do" that needs the "end," not the "each."

···

--
Posted via http://www.ruby-forum.com/\.

ts wrote:

> psfiles = Dir.glob('*.ps')
> psfiles.collect!{ |psfile| File.basename(psfile, '.ps') }
> psfiles.each do |psfile|
> puts psfile
> FileUtils.cp("psfile", psfile + ".pageinfo")

There is another problem, you have removed the suffix .ps with
File::basename, best to write it

      FileUtils.cp(psfile + ".ps", psfile + ".pageinfo")

Guy Decoux

Now that worked! Thank you!

···

--
Posted via http://www.ruby-forum.com/\.