This script will sort a directory of your choosing. You can choose to sort by either creation date or last modified. This is espcially useful for drives/directories that contain thousands of unsorted pictures. The script will unpack all files from the passed directory and it's sub directories. It will then move them into a new directory, which it will then sort.
How to Run (or follow the example):
- Clone Repo
- Navigate to some/file/path/sort-files
- If you do not have pipenv installed, install it using
$ pip install pipenv
$ pipenv install
$ pipenv run python sort_files.py
Enjoy your sorted files.
Note: There is a 0% chance of your files being deleted. No deleting occurs at any point during the sorting of your files. As a result you will be left with two directories:
- Source_Dir
- Source_Dir-Sorted
Your source dir will contain a bunch of empty directories (if it had any within it), as all files will have been moved to the new sorted directory, feel free to delete the source dir once the script is done.
Example of file structure after sort:
+-- 2021
+-- Jan 18 2021
+-- file1.txt
+-- file2.txt
+-- Jan 19 2021
+-- Jan 20 2021
+-- Jan 21 2021
- Clone Repo
- Navigate to some/file/path/sort-files
- If you do not have pipenv installed, install it using
$ pip install pipenv
- installs pipenv
$ pipenv install
- installs dependencies
- Navigate to the directory that you want to sort, in this case "/Volumes/LEXAR\ MEDIA/DCIM/100CANON" (contains 672 images)
- Copy directory path
- Run the script using pipenv
$ pipenv run python sort_files.py
- Paste directory path from your clipboard and choose whether you want to sort by creation date or last modified.
- Go check out your sorted files.
- Note that the speed of the sort will change depending on where the directory is located. In this case, sorting the files on this 2GB SD card took about 7 seconds. When running the script on a directory of the same size stored on my internal ssd, the script took ~0.4 seconds.