How to a copy a file ?

F

Florent 'flure' C.

Hello

I'm searching a portable way of copying a file from one directory to
another in ruby. Of course I could open a file for reading, another for
writing, and copy byte per byte, but is there another way ? Or am I
missing something ?

Thanks.
 
S

Simon Strandgaard

Florent said:
I'm searching a portable way of copying a file from one directory to
another in ruby. Of course I could open a file for reading, another for
writing, and copy byte per byte, but is there another way ? Or am I
missing something ?


require 'fileutils'
# have a look at
FileUtils.cp
 
F

Florent 'flure' C.

Le Mon, 17 May 2004 23:53:04 +0900, Simon Strandgaard a écrit :
require 'fileutils'
# have a look at
FileUtils.cp

Ok, thanks :)
So I was missing something ; the FileUtils class isn't described in the
Pragmatic Programmer's Guide :(
 
S

Simon Strandgaard

Le Mon, 17 May 2004 23:53:04 +0900, Simon Strandgaard a écrit :


Ok, thanks :)
So I was missing something ; the FileUtils class isn't described in the
Pragmatic Programmer's Guide :(

The pickaxe book is unfortunatly quite old.


The RI is a commandline reference tool.. with all the goodies from pickaxe,
where everything is uptodate.

http://raa.ruby-lang.org/project/ri/


For instance

server> ri FileUtils.cp
----------------------------------------------------------- FileUtils#cp
cp(src, dest, options = {})
------------------------------------------------------------------------
Options: preserve noop verbose

Copies a file +src+ to +dest+. If +dest+ is a directory, copies
+src+ to +dest/src+.

If +src+ is a list of files, then +dest+ must be a directory.

FileUtils.cp 'eval.c', 'eval.c.org'
FileUtils.cp %w(cgi.rb complex.rb date.rb), '/usr/lib/ruby/1.6'
FileUtils.cp %w(cgi.rb complex.rb date.rb), '/usr/lib/ruby/1.6', :verbose => true


(also known as copy)
server>
 
L

Lloyd Zusman

Simon Strandgaard said:
[ ... ]

The pickaxe book is unfortunatly quite old.


The RI is a commandline reference tool.. with all the goodies from pickaxe,
where everything is uptodate.

http://raa.ruby-lang.org/project/ri/


For instance

server> ri FileUtils.cp

[ ... etc. ... ]

This sounds like a great tool. I downloaded it and I followed the
installation instructions, with the following result:

% ruby install.rb
install.rb:46:in `=~': type mismatch: String given (TypeError)
from install.rb:46

This is with the following ruby version:

ruby 1.9.0 (2004-04-19) [i386-freebsd4.0]

Perhaps ri is a bit out of date, as well?
 
G

Gavin Sinclair

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,591
Members
45,103
Latest member
VinaykumarnNevatia
Top