On Mon, Jan 26, 2004 at 12:03:23PM +0100, Andrew Kotsopoulos wrote:

> I'm looking for the "rename" shell command for the macosx version of 
> bsd.  In redhat and possibly other linux distributions the command 
> renames files and supports wildcards and multiple file conversions, as 
> you most likely know.  To be more precise here is the man page:

Interesting.  Sounds like it would make a good port.  However, check
out the misc/mmv port -- it sounds like it has very similar
functionality to the rename command you've been using.

Anyhow, it's a pretty trivial script to write.  Here's a perl verion I
cooked up in a few minutes -- use with care as it has only had minimal
testing.  Note too that the 'from' expression is actually a perl
regular expression, rather than a literal match.

#!/usr/bin/perl -w

$0 =~ [EMAIL PROTECTED]/@@;

if (@ARGV < 3) {
        die <<E_O_USAGE;
$0: Usage:
    $0 from to file...
E_O_USAGE
}                  

$::from = shift @ARGV;
$::to   = shift @ARGV;

foreach my $file (@ARGV) {
        my $nfile;

        ($nfile = $file) =~ s/$::from/$::to/;

        if ($nfile ne $file) {
                rename $file, $nfile
                        or die "$0: Couldn't rename \"$file\" to \"$nfile\" -- $!\n";
        }
}
#
# That's All Folks!
#

        Cheers,

        Matthew

-- 
Dr Matthew J Seaman MA, D.Phil.                       26 The Paddocks
                                                      Savill Way
PGP: http://www.infracaninophile.co.uk/pgpkey         Marlow
Tel: +44 1628 476614                                  Bucks., SL7 1TH UK

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to