#!/bin/bash # # Archive dangling files. # # Parameters DATE="`date +%Y%m%d%I%M%S`" LOAD="$HOME/load" IMAGES="$HOME/data/images/incoming" IMAGES_PATTERN=".*\.(png|jpg|jpeg|gif|svg)" DOC="$HOME/data/doc/incoming" DOC_PATTERN=".*\.(txt|doc|docx|rtf|pdf|sxc|csv|epub|mobi|djvu)" FIND_OPTS="-maxdepth 1 -regextype posix-egrep -iregex" # Ensure all folders exist mkdir -p $LOAD $IMAGES $DOC # Move images if [ "`find $LOAD/ $FIND_OPTS "$IMAGES_PATTERN" | wc -l`" != "0" ]; then echo "Moving images into $IMAGES/$DATE ..." mkdir -p $IMAGES/$DATE find $LOAD/ $FIND_OPTS "$IMAGES_PATTERN" -exec mv {} $IMAGES/$DATE/ \; fi # Move doc if [ "`find $LOAD/ $FIND_OPTS "$DOC_PATTERN" | wc -l`" != "0" ]; then echo "Moving docs into $DOC/$DATE ..." mkdir -p $DOC/$DATE find $LOAD/ $FIND_OPTS "$DOC_PATTERN" -exec mv {} $DOC/$DATE/ \; fi