in reply to copy files to another directory
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: copy files to another directory
by fruiture (Curate) on Feb 19, 2003 at 13:46 UTC | |
by Aristotle (Chancellor) on Feb 19, 2003 at 14:34 UTC |