add move-images.sh

This commit is contained in:
Milan Hauth 2023-10-21 15:47:48 +02:00
parent 95cbe0c6fd
commit e5dab2a18f
1 changed files with 32 additions and 0 deletions

32
move-images.sh Executable file
View File

@ -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