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

Re: more fun with parameter expansion



Clint Adams wrote:
> This is for someone who wants to take a directory tree and convert all
> the filenames (and directory names) to lowercase, replacing spaces
> with underscores.  It presumes that you are using GNU mv and have
> MARK_DIRS set.  I'm sure that someone can make it more efficient.
> 
> for i (*(/N)) {mv -v "$i" "${(L)i:gs/ /_/}"}
> for i (*/**/*(/N)) {mv -v "${${(L)i%/*/}:gs/ /_/}/${${${i#*/}%/}##*/}" "${(L)
> i:gfor i (**/*(N^/)) {mv -v "${i}" "${(L)i:gs/ /_/}"}

See zmv in the Functions/Misc directory of 3.1.9 (this version is needed
for it to work).

zmv '(**/)(*[ A-Z]*)' '${1}${(L)2/ /_}'

works on a simple test case (use the option -n just to test what it would
do).  Each parenthesis maps to a positional parameter; (**/) is a special
case and is the only sort of multi-directory pattern that works.  Looks
like zmv needs the option to ignore files whose names didn't change (it's a
pain having to make the LH pattern so specific).  I'd appreciate any
feedback about zmv.

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxxxxxxxxx>
Work: pws@xxxxxxxxxxxxxxxxxxxxxxxxx
Web: http://www.pwstephenson.fsnet.co.uk



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