Remark: Posted this in reply to an unformated dupe (Reason for the code tags comment)
Hi,i guess you were trying to do the following:#!/usr/bin/perl use File::Copy; $dest="/home/dpavu2/users1/perl/sra/"; print "the source direcotry name:\n"; chomp(my $source = <STDIN>); opendir(DIR, $sech $file(@files){ @files = grep { /\.log$/ } readdir (DIR); foreach $file(@files){ } closedir (DIR);
The Module File::Copy::Recursive is also quite practical when copying files. You should also always include#!/usr/bin/perl use strict; use warnings; use File::Copy; use File::Spec; my $dest="/home/dpavu2/users1/perl/sra/"; print "the source direcotry name: \n"; my $source = ''; chomp($source = <STDIN>); if (opendir(my $DIR, $source)){ my @files = grep { /\.log$/ } readdir ($DIR); foreach my $f (@files){ my $src = File::Spec->catfile($source , $f); my $dst = File::Spec->catfile($dest , $f); copy($src , $dst) or die "Failed to copy $src to $dest ($!)\n" +; } closedir ($DIR); } else { warn "Failed to open '$source ' for reading ($!)\n"; }
directives at the beginning of your perl code. If you don't understand an error message thenuse strict; use warnings;
might create error messages which make more sense to you.use diagnostics;
In reply to Re: how to a specific group of files from source directory to destination directory
by rminner
in thread how to a specific group of files from source directory to destination directory
by asdfghjkl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |