How do I loop through files in Python to identify and count duplicates? -
i have bunch of files record number of instances file occurs. here sample of data have:
i want code run through these files , record output follows in separate excel file:
name date number of files marketdataserver 30012013 2 marketdataserver 30032013 1 . . . . netstat 01012013 5 netstat 01022012 3 is there way in can done using python script?
you can create like:
import os d = {} current_dir in [dir1, dir2, dir3..] # iterates on directories files files = os.listdir(current_dir) fi in files: if fi in d.keys(): d[fi] += 1 # there, let's increment else: d[fi] = 1 # new file k, v in d.items(): # let's print file stats print 'file:', k, 'count':' v 
Comments
Post a Comment