[Nottingham] Batch file renaming
Martin
martin at ml1.co.uk
Sun Jul 20 14:27:00 BST 2008
Andrew Etches wrote:
>>>> Could someone suggest a way to rename all these files so as to strip the
>>>> trailing ".128kbps" and leave the rest of the filename and folder names
>>>> intact?
>>> OK, first:
>>>
>>> MAKE A FULL BACKUP OF EVERYTHING FIRST!
>>>
>>>
>>> For take one, try:
>>>
>>> cd to the top directory, and:
>>>
>>> find . -name '*.128k' -print | while read n ; do mv -v "${n}"
>>> "${n%.128k}" ; done
>
> Wouldn't a basic 'cd musicdir; rename ".128kbps" "" */*' do?
Indeed so, but does that work across multiple levels of hierarchy...?
Are there any versions that will work their way through a hierarchy of
directories?
eg, as for this case:
musicdir/artist/album/files.128k
musicdir/artist/anotheralbum/files.128k
musicdir/nextartist/album/files.128k
musicdir/compilation/files.128k
musicdir/genre/subgenre/obscurecat/artist/album/files.128k
... and so on.
You could alternatively use:
find musicdirroot/. -type d -exec rename ".128kbps" "" *.128kbps \;
(Mmmm... Or would the bash globbing muck that up?)
Any others?
Cheers,
Martin
--
----------------
Martin Lomas
martin at ml1.co.uk
----------------
More information about the Nottingham
mailing list