Created
March 19, 2019 02:48
-
-
Save KageKirin/02c79a892a13d43fca5744d4b6a4f290 to your computer and use it in GitHub Desktop.
This file contains 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
#!python3 | |
""" | |
A simple python script to find all file types in a folder structure. | |
call: typewalk.py <folder> [lfs] | |
optional argument 'lfs' to run 'git lfs track *.ext' for each new BINARY FILE extension | |
I used this for making a git repo out of the full Android SDK/NDK. | |
""" | |
import os, sys | |
from pathlib import Path | |
print(sys.argv) | |
root = Path(sys.argv[1]) | |
exts = [] | |
for f in root.rglob("*"): | |
if f.is_file() and f.suffix != '' and f.suffix not in exts: | |
exts.append(f.suffix) | |
with os.popen('file -b --mime-type ' + str(f), 'r') as ff: | |
ft = ff.read() | |
print(f.suffix, 'text' if ft.startswith('text') else 'binary', ft) | |
if not ft.startswith('text') and len(sys.argv) > 2 and sys.argv[2] == 'lfs': | |
os.system('git lfs track "*{}"'.format(f.suffix)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment