A few things to look at:
- You don't appear to really be using File::Find. You should already have the files before that using readdir.
- When you grep for the *.rtf files, you don't want to join the resulting list. That will flatten it into a delimited scalar.
- See the File::Copy docs. The copy method takes two arguments: a source file and a target file. If you follow the suggestions above, you will have a list of files in @select_files. You want to iterate over that and copy each one, something like this:
foreach my $file (@select_files)
{
copy($file, "C:\\temp\\$file") or die
"Failed to copy $file: $!\n";
}
I'd put some debug in along the way to see what you have as you try some of these out.
You can use File::Find something like this:
use strict;
use File::Find;
use File::Copy;
my $dir = "/tmp";
sub process_file
{
if ($File::Find::dir ne $dir)
{
$File::Find::prune = 1;
return 0;
}
return 0 if ($_ !~ /\.rtf$/);
copy($File::Find::name, "/tmp/foo/$_") or die "Failed to copy $_:
+$!\n";
return 1;
}
find(\&process_file, $dir);
Because File::Find does a full directory tree traversal by default (goes into subdirectories) I don't find it as intuitive as just reading the directory with readdir when only looking in one directory. Maybe I'm missing something in the docs that another monk can fill me in on that limits its depth. I usually use the $Find::File::prune = 1 setting as shown above, but I've never been convinced that's the easiest or best way.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.