Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #!python3
  2.  
  3. """
  4. A simple python script to find all file types in a folder structure.
  5. call: typewalk.py <folder> [lfs]
  6. optional argument 'lfs' to run 'git lfs track *.ext' for each new BINARY FILE extension
  7.  
  8. I used this for making a git repo out of the full Android SDK/NDK.
  9. """
  10.  
  11. import os, sys
  12. from pathlib import Path
  13. print(sys.argv)
  14.  
  15. root = Path(sys.argv[1])
  16.  
  17. exts = []
  18. for f in root.rglob("*"):
  19. if f.is_file() and f.suffix != '' and f.suffix not in exts:
  20. exts.append(f.suffix)
  21. with os.popen('file -b --mime-type ' + str(f), 'r') as ff:
  22. ft = ff.read()
  23. print(f.suffix, 'text' if ft.startswith('text') else 'binary', ft)
  24. if not ft.startswith('text') and len(sys.argv) > 2 and sys.argv[2] == 'lfs':
  25. os.system('git lfs track "*{}"'.format(f.suffix))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement