Skip to content

Instantly share code, notes, and snippets.

@zeerorg
Created August 1, 2016 06:21
Show Gist options
  • Save zeerorg/98275d87938d2817a1b910f30be54f07 to your computer and use it in GitHub Desktop.
Save zeerorg/98275d87938d2817a1b910f30be54f07 to your computer and use it in GitHub Desktop.
Sort files with extensions
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