Skip to content

Instantly share code, notes, and snippets.

@dumrauf
Created September 23, 2020 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dumrauf/a8abfaa4cfc7c2eb84f3c96823ee1254 to your computer and use it in GitHub Desktop.
Save dumrauf/a8abfaa4cfc7c2eb84f3c96823ee1254 to your computer and use it in GitHub Desktop.
Batch rename Google Camera App portraits for organisation in a single directory; see https://www.how-hard-can-it.be/batch-rename-google-camera-portraits/ for details
#!/bin/bash
# Stop on all errros
set -e
# Enable extended globbing
shopt -s extglob
for dir in IMG_*/
do
if [[ $(ls "${dir}"/*.jpg | wc -l) -ne 2 ]]
then
echo "Directory '${dir}' does not have exactly two files. Best to do nothing in that case."
else
echo "Directory '${dir}' has exactly two files. All good..."
pushd "${dir}"
dir_name=${dir%*/}
mv !(*_COVER.jpg) "${dir_name}.jpg"
mv *_COVER.jpg "${dir_name}_PORTRAIT.jpg"
mv * ../
popd
rmdir "${dir}"
echo "...done processing directory '${dir}'!"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment