Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: renameing numbered files



From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
Subject: Re: renameing numbered files
Date: Sat, 24 Jun 2006 21:54:22 -0700

> On Jun 25,  5:25am, Meino Christian Cramer wrote:
> } 
> }  How can I do this in a most zshy way?
> 
> autoload -U zmv
> zmv -Qf 'Example(<->).txt(On)' 'Example${(l:4::0:)$(($1+10))}.txt'
> 
> That probably deserves some explanation:

  Yes, of course! Magic always deserves some explanations ! 
  :o) :o) :o):o):o) :o) :o) :o) :o):o) :o) :o) :o) :o) :o)
 
> Either the -Q option or (#qOn) is required because zmv turns off "bare"
> glob qualifiers by default.
> 
> The -f option is required because the set of source names overlaps with
> the set of destination names (0102 is in both).
> 
> Sorting (On) forces the higher-numbered files to be renamed first,
> otherwise 0092 --> 0102 --> 0112 will result (the original 0102 would
> be lost).  If the leading zeroes weren't there, you'd need (nOn) for
> numeric sorting.
> 
> Using $(($1+10)) discards leading zeroes, so (l:4::0:) puts them back.
> 
> I suggest playing around with "zmv -n" a bit to be sure it's going to
> do what you intended.
> 

Thanks a lot Bart!
I will experiment with that...

Have a nice weekend!
mcc



Messages sorted by: Reverse Date, Date, Thread, Author