Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.