--- Michael Moore <[EMAIL PROTECTED]> wrote:
> "Usage: rename exper [files]\n";
> 
> I've got that script too, but I couldn't think of an expression to
> do s/"bunch of files"/"numerical ordered files"/g
> 
> The files he listed are supposed to change
> 
> from:
>> 1503.jpg
>> 1504.jpg
>> 1505.jpg
> 
> to:
>> 1.jpg
>> 2.jpg
>> 3.jpg
> 
> If he's got more than 9, he can't do s/150//g, and I'm not good
> enough with regex to know if the sort of naming I'm thinking
> he's asking for is possible.
> 
> If you weren't just mentioning the script as a good general
> renamer, couldn't you show us regex-neophites how to do it?

The script doesn't just do regex, it does *any* valid Perl
expression.
What he's asking for won't (AFAIK) work with a plain regex, which
is why, in my previous reply, I included this expression:

'{my $old = $_; $old =~ s/.jpg//; my $new = $old - 1502;
s/$old/$new/;}'

(That should all be on one line, but my email will probably wrap it.)

Upon further consideration, though, I'm not sure that he's just
subtracting 1502 from each filename.  It's also possible that
the desired outcome is to renumber the files sequentially, starting
from 1, whether or not there are gaps in the old sequence.  For
that, I'd need a custom script, something like this:


#!/usr/bin/perl -w
use strict;

my $i = 1;
my $file = '';

foreach $file (`ls -1 *jpg | sort -n`) {
  chomp $file;
  rename( $file, "${i}.jpg" );
  $i++;
}


--------------------
BYU Unix Users Group 
http://uug.byu.edu/ 

The opinions expressed in this message are the responsibility of their
author.  They are not endorsed by BYU, the BYU CS Department or BYU-UUG. 
___________________________________________________________________
List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list

Reply via email to