美文网首页程序猿的笔记本
python实现删除当前目录下重复文件

python实现删除当前目录下重复文件

作者: 88ea6130522d | 来源:发表于2017-10-13 10:19 被阅读3次

    python实现删除当前目录下重复文件:

    import os, sys
    d = os.getcwd()
    all_filename_list = [i for i in os.listdir('.') if os.path.isfile(i)]
    import hashlib
    not_duplicate_arr = []
    for filename in all_filename_list:
        full_filename = d + '/' + filename
        with open(full_filename, 'rb') as file:
            file_md5=hashlib.md5(file.read()).hexdigest()
            if file_md5 not in not_duplicate_arr:
                not_duplicate_arr.append(file_md5)
            else:
                os.remove(full_filename)
    

    本文最先发布于molock.cn帆的博客

    相关文章

      网友评论

        本文标题:python实现删除当前目录下重复文件

        本文链接:https://www.haomeiwen.com/subject/ebzayxtx.html