Steve Jardine wrote:
> Hiya all,
Hello,
> Here's a sceneraio:
>
>
> I have a directory tree:
>
> A-
> |->B
> |->C
> -->D-
> ->E
>
>
> In this directory tree I have possibly several same named files
> in different directories. What I want to do is to recursively
> copy all the files in the directory tree to a single directory,
> say directory F. In that directory I would like duplicate files
> names to have prepended differences.
>
> Example:
>
> A/B/t.txt
> A/C/t.txt
> A/D/E/t.txt
>
> all being copied into the directory F looking like:
>
> F/t1.txt
> F/t2.txt
> F/t3.txt
>
> Any ideas?
UNTESTED:
use File::Copy;
use File::Basename;
use File::Find;
my $from_dir = 'A';
my $to_dir = 'F';
my %count;
find sub {
my ( $name, undef, $ext ) = fileparse $_, qr/\..*/;
copy( $_, "$to_dir/$name" . ++$count{ $name } . $ext )
or warn "Cannot copy '$File::Find::name' $!";
}, $from_dir;
__END__
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>