zsh-users
 help / color / mirror / code / Atom feed
* renameing numbered files
@ 2006-06-25  3:25 Meino Christian Cramer
  2006-06-25  4:54 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Meino Christian Cramer @ 2006-06-25  3:25 UTC (permalink / raw)
  To: zsh-users


Hi,

 in a directory there are a couple of file named:

 Example0092.txt
 Example0093.txt
 Example0094.txt
 Example0095.txt
 Example0096.txt
 Example0097.txt
 Example0098.txt
 Example0099.txt
 Example0100.txt
 Example0101.txt
 Example0102.txt

 which I want to rename to:

 Example0102.txt
 Example0103.txt
 Example0104.txt
 Example0105.txt
 Example0106.txt
 Example0107.txt
 Example0108.txt
 Example0109.txt
 Example0110.txt
 Example0111.txt
 Example0112.txt

 i.e. The first file of the new range should get the number of the
 file, which would be the next new one of the old range.
 The numbers themselves are only examples here, they could be of all
 range.

 How can I do this in a most zshy way?

 Thank you very much for any help in advance !

 Keep zshing!
 mcc
 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: renameing numbered files
  2006-06-25  3:25 renameing numbered files Meino Christian Cramer
@ 2006-06-25  4:54 ` Bart Schaefer
  2006-06-25  5:12   ` Meino Christian Cramer
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2006-06-25  4:54 UTC (permalink / raw)
  To: zsh-users

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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: renameing numbered files
  2006-06-25  4:54 ` Bart Schaefer
@ 2006-06-25  5:12   ` Meino Christian Cramer
  0 siblings, 0 replies; 3+ messages in thread
From: Meino Christian Cramer @ 2006-06-25  5:12 UTC (permalink / raw)
  To: zsh-users

From: Bart Schaefer <schaefer@brasslantern.com>
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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-06-25  5:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-25  3:25 renameing numbered files Meino Christian Cramer
2006-06-25  4:54 ` Bart Schaefer
2006-06-25  5:12   ` Meino Christian Cramer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).