Skip to content

Instantly share code, notes, and snippets.

@kanazux
Created August 19, 2018 18:15
Show Gist options
  • Save kanazux/d0a08fb2c0294fa649165beb6431baa1 to your computer and use it in GitHub Desktop.
Save kanazux/d0a08fb2c0294fa649165beb6431baa1 to your computer and use it in GitHub Desktop.
#!/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