Multiple File Renaming (special Characters)

Discussion in 'Mac Programming' started by JasonWoodall, Jan 20, 2006.

  1. JasonWoodall macrumors newbie

    Jan 20, 2006
    So I'm having a problem batch renaming files with special characters in their names.
    in Bash (terminal command prompt)
    I can use this command to change files with a " at the beginning and end of the filename.
    for i in *; do mv $i ${i/\"/};done;for i in *;do mv $i ${i/%\"/};done

    My problem is that the characters I want to remove are the open and close quotes: option+[ and shift+option+[

    I tried typing those characters into the line above instead of the escaped " but no luck.

    Any ideas?
  2. iMeowbot macrumors G3


    Aug 30, 2003
    What character set are you using in Terminal? For OS X file names, you'll want Unicode input (Terminal->Window Settings form the menu, then pick Display in the Terminal inspector window, change Character set Encoding to Unicode (UTF-8) ).

    The left quote should be \342\200\234 and the right \342\200\235 ... if you are seeing \322 and \323 or question marks when you type those, you've got the wrong charset.
  3. JasonWoodall thread starter macrumors newbie

    Jan 20, 2006
    My Terminal settins are Unicode (UTF-8)

    Yeah I am seeing:
    \342\200\234 and the right \342\200\235 when I type it out, but when I list the directory after running the bash script, I get results that don't work quite right.

    I can ls \342\200\234* and it shows me all the files with ??? as the first char.
    if I then run:
    for i in *; do mv $i ${i/\342\200\234/};done
    and then ls \342\200\234*

    I just tried it and it worked... ??? Brains going a little crazy :)
    Thanks for your help.
  4. iMeowbot macrumors G3


    Aug 30, 2003
    Don't you just hate when that happens? Apple could spend a little time making ls output a little more useful. . .

Share This Page