#!/usr/bin/python import os import re import sys import shutil from os.path import join EXTENSIONS = ['.php', '.txt', '.htm', '.html', '.conf'] DEFAULT_PATH = "./" # Current directory TMP_DIR = "../helloo" # Destination path ICONV = os.system("which iconv") FROM_CHARSET = 'CP1251' TO_CHARSET = 'UTF8' def mconvert(): print "\n" * 40, "=" * 40 print "\t ICONV FOUND" print "\t DESTINATION DIR - %s " % TMP_DIR print "=" * 40 try: shutil.copytree(DEFAULT_PATH, TMP_DIR) except OSError: print "\n[!] ERROR: Directory is already aviable (%s)\n" % TMP_DIR sys.exit(0) for root, dirs, files in os.walk(DEFAULT_PATH): files_pack = [ join(root,file) for file in files for ext in EXTENSIONS if ext in file ] for nfile in files_pack: z = nfile p = re.compile('^.') without_dot = p.sub("",z) z = TMP_DIR + without_dot QUERY = "iconv -f %s -t %s %s > %s" % (FROM_CHARSET, TO_CHARSET, nfile, z) # print QUERY # debug os.system(QUERY) print "proccessing.......[%s]" % nfile def main(): if ICONV: print "\n" * 40, "[!] ERROR: ICONV not found on your system, \ install iconv package and try again" sys.exit(0) else: mconvert() if __name__ == "__main__": main()