usr bin python import os import re import sys import shutil from os pa

 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
47
48
49
50
51
52
53
54
55
#!/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()