[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] file naming



On 01 Feb 2000 14:26:18 PST, Nicholas G. Thornton wrote:

>For the project I've just been assigned, fortunately the person before me had a
>nice orderly naming system for files; unfortunately the client wants a diferent
>standard naming system. namely...
>"file-05-01.jpg"  -> "file-05.s.jpg"
>"file-05-02.jpg"  -> "file-05.t.jpg"
>
>I was wondering how one would go about automating the changing of their names,
>or more specifically which variable I'd muck around with.

Variables?!?

Using File::Find with a custom rename subroutine should work.

Save as droplet, and drop folders or files onto it.

BTW using "s" as a starting point leaves very little room for files, as
"z" corresponds with number 8.

#! perl -w
use File::Find;

sub custom_rename {
    return if -d;
    (my $newname = $_) =~ s/^(\w+-\d+)-(\d+)(\.\w+)$/"$1." .
      chr(ord('s') - 1 + $2) . $3/e or return;
    print STDERR "$File::Find::name --> $newname\n";
    if(-e $newname) {
       warn "Couldn't rename '$_' to '$newname': file already exists\n";
    } else {
       rename $_, $newname or
         warn "Couldn't rename '$_' to '$newname': $!\n";
    }
}

find \&custom_rename, @ARGV;
__END__

-- 
	Bart.

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org