Загрузка...

Microproject | Removing duplicate files in a given directory

Thread in Python created by APT29388 Nov 20, 2024. 167 views

  1. APT29388
    APT29388 Topic starter Nov 20, 2024 ГУРУ ИНВАЙТА - lolz.live/threads/8567181 :admin:
    Python
    import hashlib
    import os

    def hashFile(filename):
    BLOCKSIZE = 65536
    hasher = hashlib.md5()

    with open(filename, 'rb') as file:
    buf = file.read(BLOCKSIZE)

    while(len(buf) > 0):
    hasher.update(buf)
    buf = file.read(BLOCKSIZE)

    return hasher.hexdigest()

    if __name__ == "__main__":
    hashMap = {}
    deletedFiles = []
    filelist = [f for f in os.listdir() if os.path.isfile(f)]

    for f in filelist:
    key = hashFile(f)

    if key in hashMap.keys():
    deletedFiles.append(f)
    os.remove(f)

    else:
    hashMap[key] = f

    if len(deletedFiles) != 0:
    print('Deleted Files')

    for i in deletedFiles:
    print(i)

    else:
    print('No duplicate files found')
     
  2. KasperIX
    KasperIX Nov 20, 2024 U dont hustle - u dont eat 425 Jan 2, 2022
    :+rep:
     
    1. APT29388 Topic starter
Top
Loading...