Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!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))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement