Last active
August 16, 2019 08:07
-
-
Save swichers/1fd86d08e854fdd41d9fd2e966af4132 to your computer and use it in GitHub Desktop.
Move files into subfolders based on common names.
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/env bash | |
# Created to help group photos based on their similar naming instead of using | |
# the folders Google had them in. | |
INDIR='./Google Photos' | |
OUTDIR='out' | |
SUB_LEN=10 | |
DEBUG=0 | |
set -e | |
echo "Searching in ${INDIR}" | |
find "${INDIR}/" -type f | while read path; do | |
FN=$(basename "${path}") | |
SUB_NAME=$(echo "${FN}" | cut -c 1-${SUB_LEN}) | |
FULL_OUTDIR="${OUTDIR}/${SUB_NAME}" | |
if [ "${DEBUG}" -eq "0" ]; then | |
if [ ! -d "${FULL_OUTDIR}" ]; then | |
mkdir -p "${FULL_OUTDIR}" | |
fi | |
mv --backup=t --strip-trailing-slashes "${path}" "${FULL_OUTDIR}/${FN}" | |
else | |
echo "Would move ${path} to ${FULL_OUTDIR}/${FN}" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment