change this
if [ -d "$SCRATCH" ]; then
find $SCRATCH -type f -mtime +5 -exec rm -rf {} \; > /tmp/docs.txt
fi
into
if [ -d "$SCRATCH" ]; then
find $SCRATCH -type d -mtime +5 -exec rm -rf {} \; > /tmp/docs.txt
fi
you only search for files using the -type f
flag; use -type d
for directories