# -*- coding: cp936 -*-

import md5

import os
import sys
from time import clock as now

def cur_file_dir():
     #获取脚本路径
     path = sys.path[0]
     if os.path.isdir(path):
         return path
     elif os.path.isfile(path):
         return os.path.dirname(path)
def getmd5(filename):

    file_txt = open(filename,'rb').read()

    m = md5.new(file_txt)

    return m.hexdigest()

def main():

    #path = raw_input("path: ")
    path = cur_file_dir()

    all_md5=[]

    total_file=0

    total_delete=0

    start=now()

    for file in os.listdir(path):

        total_file += 1

        real_path=os.path.join(path,file)

        if os.path.isfile(real_path) == True:

            filemd5=getmd5(real_path)

            if filemd5 in all_md5:

                total_delete += 1

                print '删除',file#这步是显示删除哪个
                #os.remove(file)#这步是真的做删除操作

            else:

                all_md5.append(filemd5)

    end = now()

    time_last = end - start

    print '文件总数：',total_file

    print '删除个数：',total_delete

    print '耗时：',time_last,'秒'

    

if __name__=='__main__':
    main()
