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

Re: renameing numbered files



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:

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.



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