I need a script for transfering pairs of files into a folder.
I have directory with .pdf
files. For every .pdf
is a .done
(same name, just the pattern is different pdf --> done
).
The problem is, there are cases that for a .pdf
there is no .done
or for a .done
there is no .pdf
. In this case the script should ignore that specific pair of files and grab the next one.
I want to move all PAIRS of files into the other folder with that script. But no movement for a file which has no pair.
I made a script but I don't know how to make the comparison and the skip in that case:
#!/bin/bash
source directory where all files are
SOURCE_DIR=/var/xms/batch/PDF/
Name of directory you want to move the PDFs to.
DEST_DIR=/var/xms/batch/PDF/put_ready/
Create the destination directory for the moved PDFs, if it doesn't already exist.
[ ! -d $DEST_DIR ] && mkdir -p $DEST_DIR
Search for .done files starting in $SOURCE_DIR
find $SOURCE_DIR -type f -name "*.done" | while read fin
do
Try to Find the specific PDF which names the Pattern
fpdf=?????
If a file with .pdf extension exists, move the .done file to the destination dir.
In the event of a file name clash in the destination dir, the incoming file has
a number appended to its name to prevent overwritng of the existing files.
[ -f "$fpdf" ] && mv -v --backup=numbered "$fin" $DEST_DIR/
done
End of script.
SOURCE_DIR
should only point to the directory, not the files. – Panki Jul 29 '20 at 06:40