Guest User

Untitled

a guest
Jun 4th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.40 KB | None | 0 0
  1. import subprocess, os
  2. from collections import Counter
  3.  
  4. counter = Counter()
  5. for path in os.environ['PATH'].split(':'):
  6.   for filename in os.listdir(path):
  7.     output = subprocess.check_output(['file', '-b', os.path.join(path, filename)])
  8.     filetype = ' '.join(output.decode('utf-8').split()[:2])
  9.     counter[filetype] += 1
  10.  
  11. for filetype, count in counter.most_common():
  12.   print(count, filetype)
Advertisement
Add Comment
Please, Sign In to add comment