What's a canonical way to copy a file?

J

Jeremy Henty

It's easy to copy a file with File#{open,read,write}, but I'm
surprised there isn't a prepackaged (OS-independent) API for it like
Perl's File::Copy. I've haven't found any solutions in ri, Pickaxe II
or the RAA. Have I missed something?

Cheers,

Jeremy Henty
 
S

Stefan Lang

It's easy to copy a file with File#{open,read,write}, but I'm
surprised there isn't a prepackaged (OS-independent) API for it like
Perl's File::Copy. I've haven't found any solutions in ri, Pickaxe II
or the RAA. Have I missed something?

Cheers,

Jeremy Henty

You get more with Ruby's FileUtils (comes with standard Ruby since 1.8.0):

require 'fileutils'
FileUtils.cp "source", "target"

For a list of all methods with documentation:

% ri FileUtils

HTH,
Stefan
 
J

Jeremy Henty

You get more with Ruby's FileUtils

.... which *is* documented in Pickaxe II. Somehow I missed it. D'oh!
Sorry folks, I'll look more carefully in future. Thanks Stefan,
that's exactly what I was thinking of.

Cheers,

Jeremy
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top