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

From ICO wiki
Jump to navigationJump to search
(Created page with '#!/usr/bin/python # -*- coding: utf-8 -*- import hashlib import os def remove_duplicates(dir): unique = [] for filename in os.listdir(dir) if os.path.isfile(filename…')
 
No edit summary
 
Line 1: Line 1:
<source lang = "python">
#!/usr/bin/python
#!/usr/bin/python
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
Line 10: Line 11:
         if filehash not in unique: unique.append(filehash)
         if filehash not in unique: unique.append(filehash)
         else: os.remove(filename)
         else: os.remove(filename)
</source>

Latest revision as of 13:27, 28 January 2011

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