Rename files for web

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.

Answer

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.

Attribution
Source : Link , Question Author : takeshin , Answer Author : bk.

Leave a Comment