# -*- coding:gbk -*-

import os
import sys
import datetime
import re

allFileNum = 0
today = datetime.date.today()


def printPath(level, path, path1):
    global allFileNum
    '''''
    ´òÓ¡Ò»¸öÄ¿Â¼ÏÂµÄËùÓÐÎÄ¼þ¼ÐºÍÎÄ¼þ
    '''
    # ËùÓÐÎÄ¼þ¼Ð£¬µÚÒ»¸ö×Ö¶ÎÊÇ´ÎÄ¿Â¼µÄ¼¶±ð
    dirList = []
    # ËùÓÐÎÄ¼þ
    fileList = []
    # ·µ»ØÒ»¸öÁÐ±í£¬ÆäÖÐ°üº¬ÔÚÄ¿Â¼ÌõÄ¿µÄÃû³Æ(google·­Òë)
    files = os.listdir(path)
    # ÏÈÌí¼ÓÄ¿Â¼¼¶±ð
    dirList.append(str(level))
    for f in files:
        if (os.path.isdir(path + '/' + f)):
            # ÅÅ³ýÒþ²ØÎÄ¼þ¼Ð¡£ÒòÎªÒþ²ØÎÄ¼þ¼Ð¹ý¶à
            if (f[0] == '.'):
                pass
            else:
                # Ìí¼Ó·ÇÒþ²ØÎÄ¼þ¼Ð
                dirList.append(f)
        if (os.path.isfile(path + '/' + f)):
            # Ìí¼ÓÎÄ¼þ
            fileList.append(f)
            # µ±Ò»¸ö±êÖ¾Ê¹ÓÃ£¬ÎÄ¼þ¼ÐÁÐ±íµÚÒ»¸ö¼¶±ð²»´òÓ¡
    i = 0
    file1 = open(path1 + str(today) + ".txt", "a")
    for fl in fileList:
        # ´òÓ¡ÎÄ¼þ

        file = open(path + fl)
        j = 0
        if (i == 0):
            line = file.read()
            line = line.replace(" ", "").replace("\\t", "").replace(chr(9), '')
            file1.write(line)
            print(file1)
        else:
            line = file.readline()
            while line:
                if (j == 0):
                    print(line)
                    pass
                else:
                    line = line.replace(" ", "").replace("\\t", "").replace(chr(9), '')
                    line = line.split(',')
                    print(len(line[2]))
                    if (len(line[2]) == 11):
                        tmp = line[2]
                        str11 = tmp[0:8]
                        str21 = tmp[9:]
                        line[2] = str11 + '-' + str21
                    # print line[2]
                    line = ','.join(line)
                    file1.writelines(line)
                j += 1
                line = file.readline()
        file.close()
        print(fl)
        i += 1
        print(i)
        # Ëæ±ã¼ÆËãÒ»ÏÂÓÐ¶àÉÙ¸öÎÄ¼þ
        allFileNum = allFileNum + 1
    file1.close()


if __name__ == '__main__':
    #    directory = sys.argv[1]
    src_dir = 'C:\\Users\\CYSUNCN\\Desktop\\2017\\'
    des_dir = 'C:\\Users\\CYSUNCN\\Desktop\\1\\'
    #    src_dir = sys.argv[1]
    #    des_dir = sys.argv[2]
    printPath(1, src_dir, des_dir)
    print('total number of files is ', allFileNum)
