Copying

Hi altogether.

Can some tell me how to copy files?
I tried it with including “ftools.rb” but somehow it didn’t work…

in ftools.rb is a method copy(sourcefile,destfile)

how do i exactly use it?

···

Do You Yahoo!?
Sign up for SBC Yahoo! Dial - First Month Free
http://sbc.yahoo.com

in ftools.rb is a method copy(sourcefile,destfile)

pigeon% ls [bc].rb
b.rb*
pigeon%

pigeon% cat b.rb
#!/usr/bin/ruby
require 'ftools'
File::copy 'b.rb', 'c.rb'
pigeon%

pigeon% b.rb
pigeon%

pigeon% ls [bc].rb
b.rb* c.rb*
pigeon%

pigeon% head -12 lib/ftools.rb
class << File

  TOO_BIG = 1024 * 1024 * 2 # 2MB

  def catname from, to
    if FileTest.directory? to
      File.join to.sub(%r([/\\]$), ''), basename(from)
    else
      to
    end
  end

pigeon%

'class << File' means that ruby will define methods in the singleton class
(i.e. a class method). This is why `self' must be the name of the class
when you call ::copy

Guy Decoux

Benjamin Sommerfeld benlebt@yahoo.de writes:

Hi altogether.

Can some tell me how to copy files?
I tried it with including “ftools.rb” but somehow it didn’t work…

in ftools.rb is a method copy(sourcefile,destfile)

require ‘ftools’

File.copy(‘file1’, ‘file2’)

Cheers

Dave