#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import shutil 
import argparse

#查看文件后的16进制数据
def ReadBinFile(file):
    f=open(file,'rb')   #二进制打开文件
    size =os.path.getsize(file)  #获取文件大小
    print(file, size)
    checknum = 0
    for i in range(size):
        datas = f.read(1)
        checknum += datas[0]
    f.close()
    checknum_str = '{:08X}'.format(checknum)
    print("checknum", checknum_str) 
    filename, file_type = os.path.splitext(file)   
    shutil.copyfile(file, filename+"["+checknum_str+"]"+file_type)
    return checknum



if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("n", help="bin文件名，譬如 COAB21232D.bin")

    args = parser.parse_args()
    project = str(args.n)
 
    ReadBinFile(project)
    

