Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Platform-independent copying multiple files

by tomazos (Deacon)
on Oct 18, 2005 at 09:39 UTC ( [id://500916]=perlquestion: print w/replies, xml ) Need Help??

tomazos has asked for the wisdom of the Perl Monks concerning the following question:

Let's suppose we have a $source glob string like:

  • '/home/fred/*.p
  • 'D:\\something\\*.tas'
  • 'rel/foo.*'

and a $destination like

  • '/home/anna/here'
  • '/home/anna/here/'
  • 'E:\\whatever/bing'
  • 'ting\\here\\'

I want to copy all the files from $source to $destination in a platform-independent way

At the moment the best I can think of is:

system("cp $source $destination");

Is there a better way?

-Andrew.

Replies are listed 'Best First'.
Re: Platform-independent copying multiple files
by Skeeve (Parson) on Oct 18, 2005 at 09:47 UTC
    perldoc File::Copy

    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
Re: Platform-independent copying multiple files
by Delusional (Beadle) on Oct 18, 2005 at 10:57 UTC
    cp isn't platform-independent. I beleive copy is aliased on linux systems these days, but don't rely on that.

    Your probibily better off going with Skeeve's recomendation to use File::Copy. But then again, you could go hard core, and manually open the files and bitstream binary copy through Perl, but is that really necessary (let alone safe)?
Re: Platform-independent copying multiple files
by ambrus (Abbot) on Oct 18, 2005 at 13:36 UTC

    File::Copy is a core module to copy files.

    You can use globs or the File::Glob module to find files matching the glob.

      I've used:
      my @all_matches = glob "*.txt"; my @files = grep {-f} @all_matches;
      for the glob part... :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://500916]
Approved by Skeeve
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-03-29 06:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found