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 difference)

Revision as of 13:26, 28 January 2011

  1. !/usr/bin/python
  2. -*- 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)