1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| #! /usr/bin/env python
# Sources :
# http://www.developpez.net/forums/d884109/autres-langages/python-zope/general-python/renommer-dossiers-sous-dossiers-fichiers/
# http://python.jpvweb.com/mesrecettespython/renommer_mp3
# http://python.developpez.com/faq/?page=Fichier#ContenuRepertoire
import glob
import os.path
dirToClean = "/Users/user/Music/toSort"
dirForStoring = "/Users/user/Music/namesCleaned"
i_start = len(dirToClean)
# The following variables have been built by tools_build_variables.py
UGGLY_CHARACTERS = {'Á': 'A', 'À': 'A', 'Ã': 'A', 'Â': 'A', 'Å': 'A', 'Ä': 'A', 'Ç': 'C', 'Æ': 'AE', 'É': 'E', 'È': 'E', 'Ë': 'E', 'Ê': 'E', 'Í': 'I', 'Ì': 'I', 'Ï': 'I', 'Î': 'I', 'Ñ': 'N', '': 'oe', '': 'OE', 'Õ': 'O', 'Ô': 'O', 'Ö': 'O', 'Ù': 'U', 'Û': 'U', 'Ú': 'U', 'Ü': 'U', 'á': 'a', 'à': 'a', 'ã': 'a', 'â': 'a', 'ä': 'a', 'ç': 'c', 'æ': 'ae', 'é': 'e', 'è': 'e', 'ë': 'e', 'ê': 'e', 'Ó': 'O', 'ï': 'i', 'î': 'i', 'ñ': 'n', 'Ò': 'O', 'ô': 'o', 'ö': 'o', 'ù': 'u', '': 'Y', 'û': 'u', 'ü': 'u', 'ÿ': 'y'}
CHARACTERS_ALLOWED = " -_,'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + os.sep
def cleanString(stringToClean):
prettyString = ''
for oneChar in stringToClean:
if oneChar in UGGLY_CHARACTERS:
prettyString += UGGLY_CHARACTERS[oneChar]
elif oneChar in CHARACTERS_ALLOWED:
prettyString += oneChar
else:
raise ValueError('Unknown character : ' + oneChar + '\nString build : ' + prettyString)
return prettyString
def listdirectory(path):
fichier=[]
for root, dirs, files in os.walk(path):
for oneObject in files:
path = os.path.join(root, oneObject)[i_start:]
print('path')
print(path)
print(cleanString(str(path)))
listdirectory(dirToClean) |
Partager