in reply to copy files to another directory
A few things to look at:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: copy files to another directory
by Anonymous Monk on Feb 19, 2003 at 15:08 UTC |