Rename photos automatically using Python and Cron

Last edited on 2024-06-08 Tagged under  #python   #programming   #linux 

Sometimes photo files are created with prefix "IMG_*", or saved in uppercase, or with suffix ".jpeg", or something else entirely. So I finished writing a script to rename photo(s) using the datetime_original attribute from EXIF metadata in format YYYYMMDD_HHMMSS.jpg. Learned some new Python tricks!

Setting this up with a daily cronjob will automatically locate and rename new photos to the desired format.

Note: if using pyenv (as I do) with a script that imports modules that were installed inside a pyenv environment, running that script from cron will fail (because the system python is missing the module). Its necessary to run the script with .pyenv/shims/python.

Example of a cronjob that runs daily at 12:10 :

10 12 * * * /home/<user_name>/.pyenv/shims/python /home/<user_name>/bin/rename_photo.py /home/<user_name>/image/photo/

Source: rename_photo.py Requires: exif

You can like, share, or comment on this post on Mastodon 💬

Thanks for reading! Read other posts?

« Previous: Manage multiple Python versions in Linux using pyenv