Files
eoy-pdf-sortandmerge/Sort_and_Merge_Files.sh
T

27 lines
994 B
Bash

#!/bin/bash
#get directory for pdf files
#get output directory for files
#Get the location of the PDF files
echo "What is the location of the PDF files"
read FILE
for FILENAME in $FILE
do
#The next Line assigns the number of pages to the value LOCATION to be used for were the file goes
LOCATION=$(pdfinfo "$FILENAME" | grep Pages: | awk '{print $2}')
#Test if the file exists and if it does move it to Temp.pdf to be merged back to its original location.
if test -f /mnt/tmpfs/Statement-Pages-$LOCATION.pdf; then
mv /mnt/tmpfs/Statement-Pages-$LOCATION.pdf /mnt/tmpfs/temp.pdf
else
pdfunite "$FILENAME" /mnt/tmpfs/temp.pdf /mnt/tmpfs/Statement-Pages-$LOCATION.pdf
#IF the file doesn't exist create the file with the merge.
pdfunite "$FILENAME" /mnt/tmpfs/Statement-Pages-$LOCATION.pdf
fi;
#once everything else is doen Make the directory to place the files into
#and copy the finished files into it.
mkdir $FILE/Finished/
cp -r /mnt/tmpfs/Statement-* $FILE/Finished/
done
exit