Hello
You might try the following script for such file names starting with exactly 5 or 6 digits. This will ignore other names.
* For simplicity, script will not consider year part being 15 or 16 in pattern matching and consequently it will process 5 digits 16* name and 6 digits 15* name as well, such as
16188a.jpg -> 160000/160100/16188/16188a.jpg
151288a.jpg -> 150000/151200/151288/151288a.jpg
--APPLESCRIPT
set src to (choose folder with prompt "Choose source folder where source tree is rooted at")'s POSIX path
set dst to (choose folder with prompt "Choose destination folder where destination tree is rooted at")'s POSIX path
if dst starts with src then error "Source tree may not contain destination." number 8000
set args to ""
repeat with a in {src, dst}
set args to args & a's quoted form & space
end repeat
do shell script "/bin/bash -s <<'EOF' - " & args & "
SRC=${1%/}
DST=${2%/}
{
export LC_CTYPE=UTF-8
while IFS= read -r -d $'\\0' f
do
n=${f##*/}
[[ $n =~ ^(([0-9]{2})([0-9]{1,2})[0-9]{2})[^0-9] ]] || continue # 6-digit (yymmkk) or 5-digit (yymkk)
p=${BASH_REMATCH[1]}
y=${BASH_REMATCH[2]}
m=${BASH_REMATCH[3]}
m='0'$m
m=${m: -2}
jpg=${DST}/${y}0000/${y}${m}00/${p}/JPEG
psd=${DST}/${y}0000/${y}${m}00/${p}/PSD
[[ -d $jpg ]] || mkdir -p \"$jpg\" || continue
[[ -d $psd ]] || mkdir -p \"$psd\" || continue
cp -v -pPR \"$f\" \"$jpg\"
done < <(find \"$SRC\" -type f -iname '*.jpg' -print0)
} 2>&1
exit 0
EOF"
--END OF APPLESCRIPT
And in case, the following script will normailse the parent folder name to 6 digits even for file name starting with 5 digits, such as.
15188a.jpg -> 150000/150100/150188/15188a.jpg
--APPLESCRIPT
set src to (choose folder with prompt "Choose source folder where source tree is rooted at")'s POSIX path
set dst to (choose folder with prompt "Choose destination folder where destination tree is rooted at")'s POSIX path
if dst starts with src then error "Source tree may not contain destination." number 8000
set args to ""
repeat with a in {src, dst}
set args to args & a's quoted form & space
end repeat
do shell script "/bin/bash -s <<'EOF' - " & args & "
SRC=${1%/}
DST=${2%/}
{
export LC_CTYPE=UTF-8
while IFS= read -r -d $'\\0' f
do
n=${f##*/}
[[ $n =~ ^([0-9]{2})([0-9]{1,2})([0-9]{2})[^0-9] ]] || continue # 6-digit (yymmkk) or 5-digit (yymkk)
y=${BASH_REMATCH[1]}
m=${BASH_REMATCH[2]}
k=${BASH_REMATCH[3]}
m='0'$m
m=${m: -2}
jpg=${DST}/${y}0000/${y}${m}00/${y}${m}${k}/JPEG
psd=${DST}/${y}0000/${y}${m}00/${y}${m}${k}/PSD
[[ -d $jpg ]] || mkdir -p \"$jpg\" || continue
[[ -d $psd ]] || mkdir -p \"$psd\" || continue
cp -v -pPR \"$f\" \"$jpg\"
done < <(find \"$SRC\" -type f -iname '*.jpg' -print0)
} 2>&1
exit 0
EOF"
--END OF APPLESCRIPT
Good luck,
H