Reputation: 531
I am trying to find the duplicate images present in a directory and remove them from the original directory and save them in a different directory.Till now I am able to find the duplicate images,but I am not able to remove them from original folder and save the duplicate images in the new folder.
import sys
import os
import hashlib
dir ='/Users/Documents/LiClipse Workspace/cnf/duplicate_image'
uniquelist =[]
count = 0
for dirpath, dirs, files in os.walk('image'):
files = sorted(files)
for filename in files:
with open(os.path.join(dirpath, filename)) as f:
im= f.read()
hash=hashlib.md5(im).hexdigest()
if hash not in uniquelist:
uniquelist.append(hash)
else:
print hash
Please help me how I can remove it from my original folder and save it to my new directory.Thanks a lot in advance. Apologies if it is a stupid question
Upvotes: 1
Views: 77
Reputation: 3165
You can use shutil or os module. The syntax is something similar to
import os, shutil
os.rename("source", "destination")
#or
shutil.move("source", "destination")
Upvotes: 4