File::Find is almost certainly what you're after, although the man page is a bit much to digest if you've never seen it before.

The big power of File::Find lays in the "wanted" function that you pass it. This can do pretty much anything you want. If (for example) you wanted to take each file you find and print it in rot13 to stdout, you could do something like this:

#!/usr/bin/perl -w use strict; use File::Find; # The shift here takes the first command line # argument and uses that as our path. find(\&rot_cat,shift); sub rot_cat { unless (open(INFILE,$_)) { warn "Can't open $_ - $!\n"; return; } local $/ = undef; # Slurp mode. my $contents = <INFILE>; # Rot13 our contents. $contents =~ tr/A-Za-z/N-ZA-Mn-za-m/; # Print our new file. print $contents; }
If you're copying files, your task is a little more tricky, as you'll need to create directories along the way, and make sure you know where in the source tree you are, and ensure you copy files to the appropriate plate in the destination tree.

Personally, if you're just copying trees of files around, I'd suggest you look at good ol' "cp -r" if you're on a UNIX flavoured system. It's much more understandable and obvious, and does its job extremely well. Indeed, doing a "cp -r" and then using File::Find will usually be a simplier problem to solve.

Cheers,
Paul


In reply to Re: How do I copy files in a dir and continue into each subdir? by pjf
in thread How do I copy files in a dir and continue into each subdir? by DavidZen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.