in reply to how to a specific group of files from source directory to destination directory
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how to a specific group of files from source directory to destination directory
by asdfghjkl (Initiate) on Oct 20, 2007 at 09:15 UTC | |
by roboticus (Chancellor) on Oct 20, 2007 at 12:55 UTC | |
by blazar (Canon) on Oct 20, 2007 at 13:04 UTC | |
|
Re: how to a specific group of files from source directory to destination directory
by asdfghjkl (Initiate) on Nov 05, 2007 at 00:58 UTC |