import os from shutil import copyfile types = [] files = [f for f in os.listdir('.') if os.path.isfile(f)] for f in files: ext = f.split('.')[-1] dirr = 'Chategorized/' + ext + "-files" if ext not in types: if not os.path.exists(dirr): os.makedirs(dirr) copyfile(f, dirr + '/' + f)