I am trying to build a script that can help me in traversing through all the files in a directory and to identify its file type. At the end the result should print the total count of each file type that were identified. I am using the magic library to identify the file type based on MIME.
for filename in os.listdir(os.getcwd()):
print filename
with magic.Magic(flags=magic.MAGIC_MIME_TYPE) as m:
t = m.id_filename(filename)
print t
The identification piece is pasted above which seems to be working fine but I am not sure how to store the identified filetypes and their count. The output should look like: filetype1 count filetype2 count ... ...
Please guide me as to what should be the ideal way of doing it.
new_list, andfrom collections import CountertoCounter(new_list)