🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.linux.isp
Article #8

Re: help in linux shell script in copying files

#8
From: John W. Krahn
Date: Wed, 29 Jan 2003 22:34
44 lines
2320 bytes
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
Technical Details
Message-ID: <3E3856F8.13F4106A@acm.org>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!snoopy.risq.qc.ca!newsfeed.telusplanet.net!news2.telusplanet.net.POSTED!53ab2750!not-for-mail
References: <b19idc$mb42@imsp212.netvigator.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 102983,9b430d37aa564f05
X-Google-Attributes: gid102983,public
X-Google-Thread: fe70d,9b430d37aa564f05
X-Google-Attributes: gidfe70d,public
X-Google-Thread: 1103af,9b430d37aa564f05
X-Google-Attributes: gid1103af,public
X-Google-Thread: 102b32,9b430d37aa564f05
X-Google-Attributes: gid102b32,public
X-Google-Thread: 106e9e,9b430d37aa564f05
X-Google-Attributes: gid106e9e,public
X-Google-ArrivalTime: 2003-01-29 14:34:41 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!snoopy.risq.qc.ca!newsfeed.telusplanet.net!news2.telusplanet.net.POSTED!53ab2750!not-for-mail
Message-ID: <3E3856F8.13F4106A@acm.org>
From: "John W. Krahn" <krahnj@acm.org>
X-Mailer: Mozilla 4.79 [en] (X11; U; Linux 2.4.4-4GB i586)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: alt.comp.linux.isp,aus.computers.linux,comp.os.linux.hardware,comp.os.linux.misc,comp.os.linux.security
Subject: Re: help in linux shell script  in copying  files
References: <b19idc$mb42@imsp212.netvigator.com>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Lines: 44
Date: Wed, 29 Jan 2003 22:34:41 GMT
NNTP-Posting-Host: 64.180.179.194
X-Trace: news2.telusplanet.net 1043879681 64.180.179.194 (Wed, 29 Jan 2003 15:34:41 MST)
NNTP-Posting-Date: Wed, 29 Jan 2003 15:34:41 MST