01 sometitle.mp3
02 anothertitle.mp3
...
13 someothertitle.mp3
find . -name "*.mp3" -exec mv {} $(echo {} | sed -e 's/^..//') \;$(echo {} | sed -e 's/^..//') expands to a blank, and so mv complains of a missing argument.
#!/usr/bin/python
import os
import string
import sys
if len(sys.argv) > 1:
musicDir = sys.argv[1]
else:
musicDir = '.'
musicDir = os.path.abspath(musicDir)
if not os.path.exists(musicDir):
sys.exit('Invalid directory')
filenames = [name for name in os.listdir(musicDir) if name.endswith('.mp3')]
for name in filenames:
newName = name.lstrip(string.digits + ' ')
os.rename(os.path.join(musicDir, name), os.path.join(musicDir, newName))
------------------------find . -type f -name '*mp3' | while read file do mv "$file" "`echo $file | sed 's/[0-9][0-9] //;'`" doneYou've got to be careful of the spaces in the file names. Also note that I used backticks; ICGAFF if they're "deprecated" -- I have scripts older than folks who advocate this change.
Dir.open('.'){|d| d.entries.each{|e| File.rename(e, e.split(' ')[1..-1].join(' ')) if e =~ /^[0-9]+ .*\.mp3$/}}for x in *.mp3; do mv "$x" `echo "$x" | cut -d ' ' -f 2`; done$ renamer --perl-regexp="^\d\d " "" *.mp3
'01 xyzzy.mp3' -> 'xyzzy.mp3'
'02 asdfasdxyzzy.mp3' -> 'asdfasdxyzzy.mp3'
'03 foo.mp3' -> 'foo.mp3'Rhomboid, one never writes shell for speed, merely expediency.Speak for yourself. As a programmer there is something inherently appealing about finding the "correct" solution and just going with the first thing that works, however ugly it may be. If that doesn't appeal to you, then fine. But don't assume that just because you don't care that there's no reason to worry about these things.
for f in *; do mv "$f" "${f:3}"; done
mv {} \$\(echo {} \| sed -e 's/^..//'\) \;
might work better (I don't do a lot of shell programming through).
posted by sbutler at 4:14 PM on December 11, 2005