39 lines
894 B
Bash
Executable File
39 lines
894 B
Bash
Executable File
#!/usr/bin/env zsh
|
|
|
|
# copy photos with exif data on them into a date-structured directory hierarchy
|
|
|
|
# source and destination locations
|
|
srcdir="$CAM_PIC_SRC"
|
|
picdir="$(xdg-user-dir PICTURES)/cam"
|
|
|
|
start=1
|
|
total=`ls $srcdir | wc -l`
|
|
|
|
for f in `ls $srcdir`
|
|
do
|
|
progress="$start/$total"
|
|
start=$((start+1))
|
|
|
|
src="$srcdir/$f"
|
|
|
|
# get the exif create date and turn it into a filepath
|
|
datestr=`exiftool -CreateDate "$src"`
|
|
datedir=`echo "$datestr" | awk '{ gsub(":","/",$4); print $4; }'`
|
|
datedir="$picdir/$datedir"
|
|
|
|
# make sure the destination exists
|
|
[ ! -d $datedir ] && mkdir -p $datedir
|
|
|
|
dest="$datedir/$f"
|
|
|
|
# if the file exists, don't overwrite
|
|
if [ -f $dest ]; then
|
|
print "[$progress] skipping $src->$dest: destination file already exists"
|
|
else
|
|
print "[$progress] sync $src -> $dest"
|
|
rsync $src $dest
|
|
fi
|
|
done
|
|
|
|
exit 0
|