#!/usr/bin/env python
# coding: UTF-8
import sys
import os
import chardet
def print_usage():
print '''usage:
change_charset [file|directory] [charset] [output file]\n
for example:
change utf-8
change utf-8
change . utf-8
change
'''
def get_charset(s):
return (s)['encoding']
def remove(file_name):
(file_name)
def change_file_charset(file_name, output_file_name, charset):
f = open(file_name)
s = ()
()
if file_name == output_file_name or output_file_name == "":
remove(file_name)
old_charset = get_charset(s)
u = (old_charset)
if output_file_name == "":
output_file_name = file_name
f = open(output_file_name, 'w')
s = (charset)
(s)
()
def do(file_name, output_file_name, charset):
if (file_name):
for item in (file_name):
try:
if (file_name+"/"+item):
do(file_name+"/"+item, "", charset)
else:
change_file_charset(file_name+"/"+item, "", charset)
except OSError, e:
print e
else:
change_file_charset(file_name, output_file_name, charset)
if __name__ == '__main__':
length = len()
if length == 1:
print_usage()
elif length == 2:
do([1], "", "utf-8")
elif length == 3:
do([1], "", [2])
elif length == 4:
do([1], [3], [2])
else:
print_usage()