''' Created on 19 oct. 2011 @author: abderrazek boufahja ''' from xml.dom import minidom import dircache import re import os import os.path import datetime class AZIPManager: def __init__(self): pass def _updateConceptList(self, content): return content.replace('', '') def renameFile(self, filepath): fio = FileIOExtra() content = fio.getOriginalFile(filepath) content = self._updateConceptList(content) m = re.search('.*? ' + m.group(1) basename = os.path.basename(filepath) newFileName = filepath.replace(basename, 'res/' + m.group(1) + '_fr.xml') fio.saveXMLFile(content, newFileName) def renameAllFile(self, filepath): if (os.path.exists(filepath)): list_output = dircache.listdir(filepath) for fileout in list_output: if os.path.isfile(filepath + '/' + fileout): self.renameFile(filepath + '/' + fileout) ## # # FileIOExtra Class is used to read and write from a text file # ## class FileIOExtra: def __init__(self): pass def saveXMLFile(self, content, fileName): fich = open(fileName,'w') fich.write(content.encode('utf-8')) fich.close() def getOriginalFile(self, fileName): res = '' if os.path.exists(fileName): fich = open(fileName,'r') res = fich.read() fich.close() return res if __name__ == '__main__': az = AZIPManager() ss = '/Users/aboufahj/Downloads/testContenuCDA/jeuxDeValeurs' az.renameAllFile(ss)