Created
August 19, 2018 18:15
-
-
Save kanazux/d0a08fb2c0294fa649165beb6431baa1 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import os | |
from subprocess import call, check_output | |
files = check_output(['find . -type f -maxdepth 1'], shell=True).split('\n') | |
for f in files: | |
try: | |
print(f) | |
f_type = check_output(['file -b "{}"'.format(f[2:])], | |
shell=True).split(',')[0] | |
if not os.path.isdir(f_type): | |
os.mkdir(f_type, 755) | |
call(['mv "{}" "{}"'.format(f, f_type)], shell=True) | |
except Exception as error: | |
print(error) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment