You are not logged in.
Pages: 1
Hi,
I want to rename files containg special characters in a directory tree.
For example I want
06\ --\ Doppelgänger.flacrenamed to
06\ --\ Doppelganger.flacI have found a python script that seems to be able to do it here.
I have also found a list of replacements characters
my $AccentedChars = '€–‚ƒ„…†‡ˆ‰Š‹Œ–Ž––''""•–—˜™š›œ–žŸ'.
'–¡¢£¤¥¦§¨©ª«¬-®¯°±²³´µ¶·¸¹º»¼½¾¿'.
'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞß'.
'àáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ';
my $NonAccenChars = 'E-,f,.++^%S_O-Z--````.--~Ts_o-zY'.
'-!cLoYlS`Ca_--R-`+23`uP.,10_qh3_'.
'AAAAAAACEEEEIIIIDNOOOOOxOUUUUYTS'.
'aaaaaaaceeeeiiiidnooooo%ouuuuyty';from this perl script (which throws an error when used. Otherwise it would be perfect).
So, can somebody tell me how I could feed the python script with the above replacement table?
I have tried but I can't seem to get it to work.
I have also tried to make a simple bash-script using rename but I could not that to work either.
I would really appreciate any help.
Thanks,
Rasmus
Arch x64 on Thinkpad X200s/W530
Offline
I didn't try the perl script, but sed's y command will do exactly this. tr complains about a dash
accent='€–‚ƒ„…†‡ˆ‰Š‹Œ–Ž––''""•–—˜™š›œ–žŸ–¡¢£¤¥¦§¨©ª«¬-®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ'
nonaccent='E-,f,.++^%S_O-Z--````.--~Ts_o-zY-!cLoYlS`Ca_--R-`+23`uP.,10_qh3_AAAAAAACEEEEIIIIDNOOOOOxOUUUUYTSaaaaaaaceeeeiiiidnooooo%ouuuuyty'
echo '06\ --\ Doppelgänger.flac' | sed "y/$accent/$nonaccent/"So you could do something like
for file in *; do
mv -v -i -- "$file" "$(echo "$file" | sed "y/$accent/$nonaccent/")"
doneOffline
Hi,
Thanks. That is a nice simple solution. I will try it out tonight.
Can one easily make it recursive? My files are stored as
Artist\Album\*.flacI am guessing one could just say
for file in */*/*; do
...Also, does one need to define $file to only be files which actually contains special characters?
Thanks,
Rasmus
Arch x64 on Thinkpad X200s/W530
Offline
Yeah, you could even do for file in */*/*.flac
Or
shopt -s globstar
for file in **/*.flac; do ...mv won't mess up the file if it doesn't contain special characters, like mv a a. You could add >2/dev/null after the command to hide the messages and see the actual work.
Offline
Pages: 1