import io
import chardet
import os
import codecs


def file_convert(filename):
    convert_filename = ' 변환 파일 명'

    bytes = min(32, os.path.getsize(filename))
    raw = open(filename, 'rb').read(bytes)

    if raw.startswith(codecs.BOM_UTF8):
        encoding = 'utf-8-sig'
    else:
        result = chardet.detect(raw)
        encoding = result['encoding']

    infile = io.open(filename, 'r', encoding=encoding)
    data = infile.read()
    infile.close()

    oo = open(convert_filename, 'w', encoding='UTF8')
    oo.write(data)
    oo.close()

    return convert_filename