Here is a python script that sorts files in a directory by file extension.
The directory to be sorted and the file endings to be sorted are taken as input parameters.
As an example, the script can be immensely helpful in creating order in a download folder that has grown and grown over time.
This script first checks if the specified directory is valid. If it is, it iterates through all the files in the directory and checks their file extensions. If the file extension is one of the file endings specified in the input parameters, the file is moved to a sub-folder named after the file extension. The subfolder is created if it doesn’t exist yet.
This script keeps track of the number of files moved for each file extension in the files_moved dictionary. It also keeps track of the number of files not moved in the directory in the files_not_moved variable. At the end of the script, it prints out the number of files moved per file extension and the number of files not moved in the directory.
You can download the sourcecode from my github repository:
https://github.com/smartDevel/fileSorter
Comments