Skript, mis otsib üles duplikaatfailid - Python: Difference between revisions

From ICO wiki
Jump to navigationJump to search
(Created page with 'Midagi sellist <source lang = "python"> #!/usr/bin/python # -*- coding: utf import hashlib import os def remove_duplicates(dir): unique = [] for filename in os.listdir(di…')
 
No edit summary
Line 12: Line 12:
         filehash = md5.md5(file(filename).read()).hexdigest()
         filehash = md5.md5(file(filename).read()).hexdigest()
         if filehash not in unique: unique.append(filehash)
         if filehash not in unique: unique.append(filehash)
         else: os.remove(filen
         else: os.remove(filename)
</source>
</source>

Revision as of 13:23, 28 January 2011

Midagi sellist

#!/usr/bin/python
# -*- coding: utf
import hashlib
import os 
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)