Answers for "python avoid generating duplicate files"

1

python duplicate file

>>> import shutil
>>> # Copy the file in same folder with different name
>>> shutil.copy('original.txt', 'duplicate.txt')
'/home/username/duplicate.txt'
>>> shutil.copy('original.txt', 'my_folder/duplicate.txt')
'/home/username/my_folder/duplicate.txt'
Posted by: Guest on August-10-2021
0

how to remove duplicate files from folder with python

def remove_duplicates(dir):
    unique = []
    for filename in os.listdir(dir):
        if os.path.isfile(filename):
            filehash = md5.md5(file(filename).read()).hexdigest()
            if filehash not in unique: 
                unique.append(filehash)
            else: 
                os.remove(filename)
Posted by: Guest on September-05-2021

Code answers related to "python avoid generating duplicate files"

Python Answers by Framework

Browse Popular Code Answers by Language