in reply to Re^2: Copying files from a directory to cwd
in thread Copying files from a directory to cwd

Use File::Find
use File::Copy; use File::Find; use strict; use warnings; my %files = map {$_ => 1} qw(data.txt datascript.pl); find(sub { copy($File::Find::name, '.') or die "Can't cp $File::Find::name: $ +!" if delete $files{$_}; }, 'C:\\files');

Update: change error message to display full path instead of just file name

Replies are listed 'Best First'.
Re^4: Copying files from a directory to cwd
by Anonymous Monk on Apr 21, 2011 at 05:40 UTC

    I changed the script a little bit as below,am geting the following error,the change is am passing the directory location to search as an argument,the location can be a server,how to find these files if it is on some server location?

    #!/usr/bin/perl -w use strict; use warnings; use Net::Telnet; use Net::FTP; use File::Copy; use File::Find; my $modem_build_location; $dir=$ARGV[0]; opendir(DIR, "$dir") || die "Error in opening dir $dir $!"; print "\n$modem_build_ms\n"; my %files = map {$_ => 1} qw(data.txt datascript.pl); find(sub { copy($File::Find::name, '.') or die "Can't cp $_: $!" if delete $files{$_}; }, $dir); close DIR; ERROR:- Can't cp datascript.pl: at Modem_images.pl line 19.

      Change the error message to be more explicit, as the filename alone isn't revealing of what your problem might be:

      copy($File::Find::name, '.') or die "Can't cp $File::Find::name: $ +!"

      Can anyone help?

Re^4: Copying files from a directory to cwd
by Anonymous Monk on Apr 21, 2011 at 07:42 UTC

    This is not working,I am getting error Can't cp datafiles.txt: at Modem_images.pl line 19