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
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Midagi sellist
http://stackoverflow.com/questions/2399196/finding-duplicate-files-by-content-across-multiple-directories
 
<source lang = "python">
#!/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(filen
</source>

Latest revision as of 23:17, 24 October 2011