Created
July 31, 2019 08:48
-
-
Save ElectricCoffee/a59a703951122afa928048ed30587df0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! python | |
import os, sys, mimetypes, pprint | |
from typing import Optional, Dict | |
# Lists the file types and their associated line endings in a file tree | |
types: Dict[str, list] = {} | |
def guess_filetype(path: str) -> Optional[str]: | |
"""Returns just the type returned by mimetypes.guess_type, not its encoding""" | |
return mimetypes.guess_type(filepath)[0] | |
if len(sys.argv) <= 1: | |
print('Please supply a root folder') | |
exit() | |
root = os.path.abspath(sys.argv[1]) | |
for folder, _, files in os.walk(root): | |
for file in files: | |
filepath = os.path.join(folder, file) | |
filetype = guess_filetype(filepath) | |
if not filetype: continue | |
__, extension = os.path.splitext(filepath) | |
if filetype in types.keys(): | |
if extension in types[filetype]: | |
continue | |
else: | |
types[filetype].append(extension) | |
else: | |
types[filetype] = [extension] | |
for k, v in types.items(): | |
print(k, v) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment