Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Renaming thingy
- X-seq: zsh-users 11482
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: Renaming thingy
- Date: Mon, 14 May 2007 18:24:43 +0100
- In-reply-to: <20070514170239.GC6929@solfire>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20070514170239.GC6929@solfire>
meino.cramer@xxxxxx wrote:
> Hi,
>
> I have a directory tree with different directories
> on different levels.
> There are files scattered around there, some of then
> are named *.JPG.
> I want to rename them, starting at the root of that tree
> to *.jpg.
> Furthermore some of the directories contain spaces in
> their names. I want to replace the spaces by underscores.
>
> Is there a compact way to accomplish this with zsh?
Do it in two stages.
autoload -U zmv
zmv '(**/)(*).JPG' '$1$2.jpg'
zmv '(**/)(*)(#q/)' '$1${2// /_}'
This is guaranteed to be depth first. So first it renames .JPG files,
then it renames directories starting with the end component. This
should mean all the generated "mv"s operate on existing file names.
I think.
--
Peter Stephenson <pws@xxxxxxx> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
To access the latest news from CSR copy this link into a web browser: http://www.csr.com/email_sig.php
To get further information regarding CSR, please visit our Investor Relations page at http://ir.csr.com/csr/about/overview
Messages sorted by:
Reverse Date,
Date,
Thread,
Author