Home > Bash, Linux, Programmering > Remove åäö from file names and folders

Remove åäö from file names and folders

#!/usr/bin/python
# -*- coding: iso-8859-15 -*-
import os

def syntax(item):
# åäö->aao
nn=item.replace('å','a').replace('ä','a').replace('ö','o')
nn=nn.replace('Å','A').replace('Ä','A').replace('Ö','O')
nn=nn.replace('ü','u').replace('Ü','U')
nn=nn.replace('é','e').replace('É','E')

#special chars -> underscore
#    for uscore in ("'",'`',"'",'^','"','¨','(',')','[',']','=',
#                   ',',':',';','*','!','@','£','#','¤','$','%','&','{','}'):
#      nn=nn.replace(uscore,'_')

return nn

for root,dirs,files in os.walk('./',topdown=False):
for name in files: # First change name of the files
newname=os.path.join(root,syntax(name))
name=os.path.join(root,name)
os.rename(name,newname)

for name in dirs: # Then change name of the folders
newname=os.path.join(root,syntax(name))
name=os.path.join(root,name)
os.rename(name,newname)
Categories: Bash, Linux, Programmering Tags:
  1. No comments yet.
  1. No trackbacks yet.