Re: adding leading zeros to a filename

From: Stephane CHAZELAS (this.address_at_is.invalid)
Date: 01/29/05


Date: Sat, 29 Jan 2005 11:05:52 +0000

2005-01-28, 19:31(+00), rupert:
> I've tried unsuccessfully to find the answer to this, so am hoping
> someone here can help...
>
> I've got a directory of photos called:
>
> 1.jpg
> 2.jpg
>
> ....
>
> 10.jpg
> 11.jpg
>
> ...
>
> 100.jpg
> 101.jpg
>
> ...
>
> and I can't for the life of me work out how to write a script to add
> leading zeros to the filenames so they are in the form
>
> 001.jpg
> 002.jpg
>
> ....
>
> 010.jpg
> 011.jpg
>
> ...
>
> 100.jpg
> 101.jpg
[...]

zsh << \EOF
autoload -U zmv
zmv '(<1->).jpg' '${(l:3::0:)1}.jpg'
EOF

-- 
Stéphane