0

Do you know any smart script to rename files for web format?
(replace all non ASCII characters, spaces, transliterate unicode chars, change case etc.)

eg.

my ójf ćżpd - ąąv - hźóż HŹŃÓKŁFU.jpg

to

my_ojf_czpd-aav_-_hzoz_HZNOKLFU.jpg

I've been playing with rename command, but there is always some new character which my regex does not support. I'm sure there is already a good tool for this task.

1 Answer 1

1

Can you use Python? This little script:

import urllib
import unicodedata
print urllib.quote_plus(unicodedata.normalize(NFKD', u'my ójf ćżpd - ąąv - hźóż ŹŃÓKŁFU.jpg').encode('ascii','ignore')).replace('+','_')

Produces your requested output of:

 my_ojf_czpd_-_aav_-_hzoz_HZNOKFU.jpg

This creates an output that is all ASCII and escapes ASCII characters not allowable in URLs. If that does what you are after it shouldn't take much to turn it into the script you need.

3
  • I have ever used Python before :) Looks promising, but how to recursive iterate the files in the directory?
    – takeshin
    Commented Jul 9, 2010 at 20:23
  • import os os.listdir(.) returns a list containing all the files in the directory Commented Jul 9, 2010 at 20:31
  • mayankjohri.wordpress.com/2008/07/02/… This works. Instead of appending the files to a list, you'll run the translation code above and then perform the rename from old to new
    – bk.
    Commented Jul 9, 2010 at 20:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .