Created
September 23, 2020 21:08
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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