D
david
Im trying to find all files ONLY in the current directory that are
called
"today.txt" or "sub.txt" and copy them to a different directory. Im
trying to do so using File::Find and File::Copy, but I cannot seem to
get this not to recurse through the directory structure. (There may be
other "today.txt" files below the current dir.
#!/usr/bin/perl -w
use strict;
use File::Find;
use File::Copy;
my $dir="./floppy";
my $curdir="./work";
opendir(DIR, $curdir) || die "$!";
sub wanted {
if ( -f $_ && ! -d $_) {
my $file = $File::Find::name;
if ($file =~ /today\.txt/ or /sub\.txt/)
{
for ($File::Find::name)
{
print "Copying $_\n";
copy $file, $dir or die "Error copying: $!";
}
}
}
}
find \&wanted, '.';
close(DIR);
-------------
Current DIR is "/work".
/work/today.txt
/work/sub.txt
/work/folder/today.txt
I only want these files from /work. Any suggestions?
Thanks!
called
"today.txt" or "sub.txt" and copy them to a different directory. Im
trying to do so using File::Find and File::Copy, but I cannot seem to
get this not to recurse through the directory structure. (There may be
other "today.txt" files below the current dir.
#!/usr/bin/perl -w
use strict;
use File::Find;
use File::Copy;
my $dir="./floppy";
my $curdir="./work";
opendir(DIR, $curdir) || die "$!";
sub wanted {
if ( -f $_ && ! -d $_) {
my $file = $File::Find::name;
if ($file =~ /today\.txt/ or /sub\.txt/)
{
for ($File::Find::name)
{
print "Copying $_\n";
copy $file, $dir or die "Error copying: $!";
}
}
}
}
find \&wanted, '.';
close(DIR);
-------------
Current DIR is "/work".
/work/today.txt
/work/sub.txt
/work/folder/today.txt
I only want these files from /work. Any suggestions?
Thanks!