can anyone suggest how I can find files in directories and subdirectories and copy them into a new directory.I tried the following code but it doesnot do the job.
[CODE=perl]$inputfile1 = "file_index.txt ";
open(INP1, $inputfile1 ) || die("cannot open $inputfile1 in MAIN");
@names = <INP1>;
close(INP1);
foreach my $ref (@names)
{
chomp($ref);
use File::Find;
my $localdir = 'C:\Data\refere nce_material\pe rl_scripts\copy \test_dataset';
find(
sub {
push @files,$File::F ind::name,if /$ref/
# print $File::Find::na me, "\n" if /\.txt$/
},
$localdir);
}
foreach my $ref (@files)
{
chomp($ref);
my $source_dir=$re f;
use File::NCopy;
my $target_dir = 'test1';
mkdir($target_d ir) or die "Could not mkdir $target_dir: $!";
my $cp = File::NCopy->new(recursiv e => 1);
$cp->copy("$source_ dir/*", $target_dir)
or die "Could not perform rcopy of $source_dir to $target_dir: $!";
}[/CODE]
[CODE=perl]$inputfile1 = "file_index.txt ";
open(INP1, $inputfile1 ) || die("cannot open $inputfile1 in MAIN");
@names = <INP1>;
close(INP1);
foreach my $ref (@names)
{
chomp($ref);
use File::Find;
my $localdir = 'C:\Data\refere nce_material\pe rl_scripts\copy \test_dataset';
find(
sub {
push @files,$File::F ind::name,if /$ref/
# print $File::Find::na me, "\n" if /\.txt$/
},
$localdir);
}
foreach my $ref (@files)
{
chomp($ref);
my $source_dir=$re f;
use File::NCopy;
my $target_dir = 'test1';
mkdir($target_d ir) or die "Could not mkdir $target_dir: $!";
my $cp = File::NCopy->new(recursiv e => 1);
$cp->copy("$source_ dir/*", $target_dir)
or die "Could not perform rcopy of $source_dir to $target_dir: $!";
}[/CODE]
Comment