Created
March 3, 2016 01:16
-
-
Save seveibar/36cfbb44f98b9f05937b to your computer and use it in GitHub Desktop.
Creates directory with filetypes for all files in specified directory
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
import shutil | |
import os | |
from os.path import join | |
import time | |
import sys | |
""" | |
USAGE | |
python filetype_sorter.py <target directory> | |
""" | |
directory = sys.argv[1] | |
files_in_dir = [(f,f.split(".")[-1]) for f in os.listdir(directory) if os.path.isfile(join(directory,f))] | |
for fi, di in files_in_dir: | |
if not os.path.isdir(join(directory, di)): | |
os.mkdir(join(directory ,di)) | |
time.sleep(.05) | |
print("Moving %s to %s" % (join(directory,fi),join(directory,di,fi))) | |
shutil.move(join(directory,fi), join(directory, di,fi)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment