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.

takeshin
  • 1,431
  • 3
  • 19
  • 28

1 Answers1

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.

bk.
  • 768
  • 1
  • 4
  • 13
  • I have ever used Python before :) Looks promising, but how to recursive iterate the files in the directory? – takeshin Jul 09 '10 at 20:23
  • import os os.listdir(.) returns a list containing all the files in the directory – Tom O'Connor Jul 09 '10 at 20:31
  • http://mayankjohri.wordpress.com/2008/07/02/create-list-of-files-in-a-dir-tree/ 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. Jul 09 '10 at 20:37