Move files to specific directory, according to file extension
I have no idea, how to make it simpler. I could only offer an alternative:

#!/usr/bin/env python

import os
import shutil

fullpath = os.path.join
python_directory = "./py"
start_directory = "./mixed"
text_files = "./txt"


def main():
    for dirname, dirnames, filenames in os.walk(start_directory):
        for filename in filenames:
            source = fullpath(dirname, filename)
            if filename.endswith("py"):
               shutil.move(source, fullpath(python_directory, filename))
            elif filename.endswith("txt"):
                shutil.move(source, fullpath(text_files, filename))

if __name__ == "__main__":
    main()


I think os.walk()is what you are looking for.