Skip to content

Sort files with Python - Sort by last modified or creation date.

License

Notifications You must be signed in to change notification settings

gfdb/sort-files

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sort Files

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):

  1. Clone Repo
  2. Navigate to some/file/path/sort-files
  3. If you do not have pipenv installed, install it using $ pip install pipenv
  4. $ pipenv install
  5. $ 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:

  1. Source_Dir
  2. 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

Step by Step

  1. Clone Repo
  2. Navigate to some/file/path/sort-files
  3. If you do not have pipenv installed, install it using

$ pip install pipenv - installs pipenv

$ pipenv install - installs dependencies

  1. Navigate to the directory that you want to sort, in this case "/Volumes/LEXAR\ MEDIA/DCIM/100CANON" (contains 672 images)

terminal

terminal

  1. Copy directory path
  2. Run the script using pipenv

$ pipenv run python sort_files.py

  1. Paste directory path from your clipboard and choose whether you want to sort by creation date or last modified.

terminal

  1. Go check out your sorted files.

terminal

  • 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.

About

Sort files with Python - Sort by last modified or creation date.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages