Re: help in linux shell script in copying files
From: John W. Krahn (krahnj@acm.org)
Date: 01/29/03
- Next message: Gerhard W. Gruber: "Re: help in linux shell script in copying files"
- Previous message: Armin Krawinkel: "Re: Port number query"
- In reply to: Laplace: "help in linux shell script in copying files"
- Next in thread: Gerhard W. Gruber: "Re: help in linux shell script in copying files"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
From: "John W. Krahn" <krahnj@acm.org> Date: Wed, 29 Jan 2003 22:34:41 GMT
Laplace wrote:
>
> if the "first letter is "A" or "a" copy it from \temp\ to \data\A\.... until
> finished A
> if the "first letter is "A" or "a" copy it from \temp\ to \data\A\.... until
> finished A to Z....
>
> algorithm
>
> if the "first letter is "A" or "a" copy it from \temp\ to \data\A\....
>
> if the "first letter is "B" or "b" copy it from \temp\ to \data\B\....
>
> up to Z....
>
> can u show me the script?
#!/usr/bin/perl -w
use strict;
use File::Copy;
my $from = '/temp';
my $to = '/data';
opendir my $dh, $from or die "Cannot open '$from' $!";
while ( defined( my $file = readdir $dh ) ) {
next unless $file =~ /^([[:alpha:]])/;
my $first = uc $1;
mkdir "$to/$first" unless -e "$to/$first";
copy( "$from/$file", "$to/$first/$file" )
or warn "Cannot copy $file to $to/$first: $!";
}
__END__
John
-- use Perl; program fulfillment
- Next message: Gerhard W. Gruber: "Re: help in linux shell script in copying files"
- Previous message: Armin Krawinkel: "Re: Port number query"
- In reply to: Laplace: "help in linux shell script in copying files"
- Next in thread: Gerhard W. Gruber: "Re: help in linux shell script in copying files"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|