Created
August 1, 2016 06:21
-
-
Save zeerorg/98275d87938d2817a1b910f30be54f07 to your computer and use it in GitHub Desktop.
Sort files with extensions
This file contains 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 os | |
import sys | |
import shutil | |
def join_path(*arg): | |
return os.path.join(current_path, *arg) | |
current_path = os.getcwd() | |
files = [ f for f in os.listdir(current_path) if\ | |
os.path.isfile(os.path.join(current_path, f)) and f != "sort_files.py" ] | |
directory = [ f for f in os.listdir(current_path) if not\ | |
os.path.isfile(join_path(f)) ] | |
extensions = [] | |
for f in files: | |
ext = f.split(".")[-1] | |
try: | |
os.mkdir(join_path(ext)) | |
#print ext | |
except: | |
pass | |
shutil.move(join_path(f), join_path(ext, f)) | |
#print extensions |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment