#!/bin/zsh # enable extended globbing required for the folder matching we do here setopt extendedglob # Folder in which the low res copies will be created dest_folder="../view_copy" # Compression factor: must be between 0.99. # Higher means higher quality but bigger size quality="60" resolution="1920x1920" # Create folder structure in destination that matches that of source. # Create only folders matching the following: # Must be in a year folder (e.g. a folder matching 2???) # Must be inside an album (e.g. a folder inside a year folder starting with an isodate - matching 2* # Ignore folders named "private" or "privat". # # Match all folders matching 2???/2* and all their subfolders, except if any of those folders are called 'private' ( for x in 2???/2*/(^(private|privat)/)#(/); do mkdir -p $dest_folder/$x; done ) # Create folder structure for "in" folders ( for x in 2???/in/(^(private|privat)/)#(/); do mkdir -p $dest_folder/$x; done ) # Delete files in destination that do not exist in the source for x in $dest_folder/**/*(.); do orig=${x#$dest_folder/} [[ -e $orig ]] || delete_candidates+=($x) done rm -fv $delete_candidates # Delete folders in destination that do not exist in the source for folder in $dest_folder/**/*(/); do orig=${folder#$dest_folder/} [[ -e $orig ]] || delete_candidates+=($folder) done rmdir $delete_candidates # Generate low res copies of photos for year in 20??; do time ( echo $year STARTING for x in $year/2*/(^(private|privat)/)#/*.(jpg|JPG)(N) ; do #echo "Checking if $dest_folder/$x older than $x" if [[ ! -e "$dest_folder/$x" ]] || [[ "$x" -nt "$dest_folder/$x" ]] ; then #echo Updating $x nice convert -quiet -quality $quality -resize $resolution $x $dest_folder/$x echo -n . else #echo Skipping $x #echo -n _ fi done echo echo $year DONE ) & #exit done ### IN FOLDERS BEGIN for year in 20??; do time ( echo $year STARTING for x in $year/in/(^(private|privat)/)#/*.(jpg|JPG)(N) ; do #echo "Checking if $dest_folder/$x older than $x" if [[ ! -e "$dest_folder/$x" ]] || [[ "$x" -nt "$dest_folder/$x" ]] ; then #echo Updating $x nice convert -quiet -quality $quality -resize $resolution $x $dest_folder/$x echo -n : else #echo Skipping $x #echo -n _ fi done echo echo $year DONE ) & #exit done # # END IN FOLDERS echo "Waiting for processes to complete" wait echo "DONE"