move files into folders and rename existing files.
Hello everyone.
A few years ago i got some help here with moving and sorting files with great success.
I have modified the script a bit for a new situation and now i'm stuck.
The script moves files into specific folders depending on the filename and if there are any existing files rename them but i cant get the rename to work. I tried with with the --backup command:
mv -v -b \"$f1\" \"$jpg\"
But all i get is illegal option, is there any other way to append existing files?
Also i'm sure there must be a better way to loop through the files instead of using two "while do" after each other, though it seems to work just fine.
Example filenames and folder structure:
15512-1.tif
15512-1.jpg
180313-1.tif
180313-1.jpg
2002005-1.tif
2002005-1.jpg
OBJECTS/2018/1803/180313/JPEG/180313-1.jpg
OBJECTS/2018/1803/180313/JPEG/180313-2.jpg
OBJECTS/2018/1803/180313/JPEG/old1_180313-1.jpg (exampl of renamed existing file)
OBJECTS/2018/1803/180313/JPEG/old2_180313-1.jpg
do shell script "/bin/bash -s <<'EOF'
SRC1=/volume1/Archive/IMAGES/UPLOAD/JPEG/
SRC2=/volume1/Archive/IMAGES/UPLOAD/TIFF/
DST=/volume1/Archive/IMAGES/OBJECTS/
{
export LC_CTYPE=UTF-8
while IFS= read -r -d $'\\0' f1
do
n=${f1##*/}
[[ $n =~ ^(([0-9]{2})([0-9]{1,2})[0-9]{2,3})[^0-9] ]] || continue #5,6 & 7-digits (yymkk) (yymmkk) (yymmkkk)
p=${BASH_REMATCH[1]}
y=${BASH_REMATCH[2]}
m=${BASH_REMATCH[3]}
m='0'$m
m=${m: -2}
jpg=${DST}/'20'${y}/${y}${m}/${p}/JPEG
[[ -d $jpg ]] || mkdir -p \"$jpg\" || continue
mv -v -b \"$f1\" \"$jpg\"
done < <(find \"$SRC1\" -type f -iname '*.jpg' -print0)
# TIFF files
while IFS= read -r -d $'\\0' f2
do
n=${f2##*/}
[[ $n =~ ^(([0-9]{2})([0-9]{1,2})[0-9]{2,3})[^0-9] ]] || continue #5,6 & 7-digits (yymkk) (yymmkk) (yymmkkk)
p=${BASH_REMATCH[1]}
y=${BASH_REMATCH[2]}
m=${BASH_REMATCH[3]}
m='0'$m
m=${m: -2}
tif=${DST}/'20'${y}/${y}${m}/${p}/TIFF
[[ -d $tif ]] || mkdir -p \"$tif\" || continue
mv -v -b \"$f2\" \"$tif\"
done < <(find \"$SRC2\" -type f -iname '*.tif' -print0)
} 2>&1
exit 0
EOF"
--END OF APPLESCRIPT
MacBook Pro 15", macOS 10.15