From e5dab2a18fc43d633fc2f8a282c219985a1d5d55 Mon Sep 17 00:00:00 2001 From: Milan Hauth Date: Sat, 21 Oct 2023 15:47:48 +0200 Subject: [PATCH] add move-images.sh --- move-images.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 move-images.sh diff --git a/move-images.sh b/move-images.sh new file mode 100755 index 0000000..7c0057e --- /dev/null +++ b/move-images.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +# run this after scan-adf.sh +# TODO maybe integrate this into scan-adf.sh + + + +find . -mindepth 1 -maxdepth 1 -type f -regextype posix-extended -regex '\./[0-9]{4}-[0-9]{2}-[0-9]{2}\.[0-9]{2}-[0-9]{2}.*\.webp' -printf '%P\n' | +while read webp_path +do + + year_month=$(echo "$webp_path" | sed -E 's/^([0-9]{4}-[0-9]{2})-.*$/\1/') + + if [[ "$year_month" == "$webp_path" ]]; then + echo "error: failed to parse year_month from webp_path: $webp_path" + exit 1 + fi + + #echo "$year_month $webp_path" + + mkdir -p "img/$year_month" + + output_path="img/$year_month/$(basename "$webp_path")" + + if [[ -e "$output_path" ]]; then + echo "error: output file exists: $output_path" + exit 1 + fi + + mv "$webp_path" "$output_path" + +done