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

Re: help with 'rename' function



Timothy J Luoma <luomat+Lists/Zsh/users@xxxxxxxxxxxxxxx> writes:

| For example, say you have a bunch of files which ended with .THIS and you  
| wanted to change them to end with .THAT
| 
| You would do
| 
| 	rename *.THIS THIS=THAT
| 	
| and it would go on its way... or if it was just one file:
| 
| 	rename foo.THIS THIS=THAT

Well, I needed to do exactly this but also do other arbitrary
rename operations to one or many files, so I first created a
"higher-order" ;) function...

rename-with-filter () {
        if ! [[ $# -lt 2 ]]
        then
                for kala in $argv[2,-1]
                do
                        mv "$kala" "$(echo "$kala" | eval $1)"
                done
        fi
}

...using which I could make, for example, a following kind of
function to transform filenames like ThisIsFilename to
This_Is_Filename:

rename_separate () {
        rename-with-filter "sed -e 's/\([a-z]\)\([A-Z]\)/\1_\2/g'" $*
}

This should handle your much simpler case too.

| I've tried to make a function which does this, but it fails:

Sorry, can't help you with your implementation, I'm pretty much
write-only zsh user :)

//Hannu



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