Rename and Iconv are like Chocolate and Peanut Butter
The features of iconv are probably built into Perl rename (aka prename), but when I tried the example from the man page, it kept generating an error message. I presume this is due to a missing Perl module. Here’s the error:
1
2
|
Use of uninitialized value $out_enc in concatenation (.) or string at /%homebrew%/bin/rename line 149.
No such encoding
|
So I suppose if we don’t care much about speed then we can just use an external utility like iconv to help convert a whole bunch of crap file names to something a little more universally-digestible. Change to the directory with the unfriendly file names and then run this rename and iconv combo to bulk rename them:
1
2
3
|
echo -n "/usr/bin/iconv -f utf-8 -t ascii//TRANSLIT" > ~/bin/2ascii
chmod +x ~/bin/2ascii
rename -P ~/bin/2ascii -Xz -e 's/_(\W)_/$1/g; s/__+/_/g;' *
|
I just renamed over two thousand files with this so I haven’t looked at all of them, but so far it looks like it’s done a great job.
rename 0.3 you can find here: http://www.perlmonks.org/?node_id=303814, but I got it from homebrew.