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

There is a small correction.All I know is that there are two files in data.txt and datascript.pl in "C:\files" directory .I dont know where these two files are exactly located inside "C:\files".How to find these two files inside C:\files and then copy?

  • Comment on Re^2: Copying files from a directory to cwd

Replies are listed 'Best First'.
Re^3: Copying files from a directory to cwd
by wind (Priest) on Apr 21, 2011 at 04:38 UTC
    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

      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?

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