Last active
November 11, 2022 01:00
-
-
Save vredesbyyrd/546e1ff669d4b17c2d3c4821fdba4477 to your computer and use it in GitHub Desktop.
small script to prune extreneous sooc jpg's - we want raw_dir == jpg_dir
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
#!/usr/bin/sh | |
# small script to prune extreneous sooc jpg's - we want raw_dir == jpg_dir | |
# takes one arg: full path to raw_dir | |
# requires 'trash-cli' package: https://github.com/andreafrancia/trash-cli | |
RAW_DIR="${1}" # user passes raw directory path | |
JPG_DIR=$(find "$RAW_DIR" -mindepth 1 -maxdepth 1 -name "*sooc" -type d) # only look dirs ending in "sooc" | |
# get all files matching .{ext}, return only the basename | |
# modified from: https://stackoverflow.com/questions/26935515/in-linux-how-to-compare-two-directories-by-filename-only-and-get-list-of-result | |
getfiles() { | |
find "$1" -maxdepth 1 -type f -regextype posix-extended -regex ".*\.(RAF|JPG)" \ | |
-exec bash -c 'for f in "$@"; do basename "${f%.*}"; done' "" {} + | sort; | |
} | |
# diff raw_dir -> jpg_dir. Compare basename only (minus ext) | |
# returns files that exist in jpg_dir and not raw_dir | |
diff=( $(grep -vxFf <(getfiles "$RAW_DIR") <(getfiles "$JPG_DIR")) ) | |
# stdout results of diff. Add results to "dirty" array | |
dirty=() | |
for filename in ${diff[@]}; do | |
filepath="${JPG_DIR}/${filename}.JPG" | |
dirty+=( "${filepath}" ) | |
echo "$filepath" | |
done | |
# ask before trashing extreneous sooc jpg's | |
printf "> \e[31mTrash\e[39m the above \033[1m%s\033[0m jpg's from \e[33m%s\e[39m (Y/n) " ${#diff[@]} "$(basename "${JPG_DIR}")" | |
read answer | |
if [ "$answer" != "${answer#[Yy]}" ] ;then | |
for filename in ${diff[@]}; do | |
printf '>> \e[31mTrashing\e[39m \e[33m%s\e[39m\n' "${filename}" | |
done | |
trash "${dirty[@]}" # for extra safety, use trash-cli rather than rm | |
printf '>> \e[31mTrashed\e[39m \033[1m%s\033[0m files\n' ${#diff[@]} | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment