copy("$File::Find::name","C:\\temp\\/$_");
Where'd $File::Find::name come from? You didn't call File::Find's find(), you read a directory yourself. You're also calling copy() only once, so at best it would copy a single file.
You correctly use grep to filter the list of all filenames, but a) why use @allfiles there when you aren't interested in directories? and b) you join the list into a single string before assigning it to the @selected_files array, where it gets assigned to the first element. Then you never do something with @selected_files again..
Something else I noticed: you're opening the directory specified in $line, yet probably confusing the user by saying "Current directory contains [..]".
#! perl -w
use strict;
use File::Copy;
use File::Spec::Functions qw(catfile);
my $line = 'C:\08\00004DC4.013';
opendir MYDIR, $line or die "Could not opendir $line: $!\n";
my @allfiles = grep { $_ ne '.' and $_ ne '..' } readdir MYDIR ;
closedir(MYDIR);
my @files = grep { !-d } @allfiles ;
my @dirs = grep { -d } @allfiles ;
print @files." files and ".@dirs." directories in $line\n" ;
print map "$_\n", @allfiles;
my @select_files = grep /\.rtf\z/i, @files;
for my $file (@select_files) {
copy catfile($line,$file), catfile("C:\\temp", $file);
}
Makeshifts last the longest.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|