前回、ファイルの変更日を修正したけど、数字だけ使ってたらバグが出たので、きちんと日付を使うことにした。
#! /bin/sh
echo "start!"
root_path="$1"
if [[ $root_path =~ .*\ +$ ]]
then
/usr/bin/osascript -e 'display notification "パス" with title "最後に半角スペースエラー"'
exit 1
fi
cd "$root_path"
FILE_EXSIT_FLG=0
for pathfile in find -P ./ -type f -maxdepth 1 -iname "*.jpg" -o -iname "*.png" -o -iname "*.mov" -o -iname "*.mp4" -o -iname "*.mkv"
; do
FILE_EXSIT_FLG=1
done
find "$root_path" -type d | sort | while read FILE01
do
if [ "${FILE_EXSIT_FLG}" = 0 ]; then
if [ "$root_path" = "${FILE01}" ]; then
continue
fi
fi
cd "${FILE01}"
for file in *
do
n=${file%.*} #070.0-_001
n=${n/_/} #070-001
n=${n/-/} #070.001
n=${n/./} #070001
n=expr $n + 0
#70001
echo $n
dt01=date -v+${n}M -j -f "%Y %m/%d %H:%M:%S" "2000 01/01 00:00:00" +"%Y:%m:%d %H:%M:%S"
dt02=date -v+${n}M -j -f "%Y %m/%d %H:%M:%S" "2000 01/01 00:00:00" +"%Y%m%d%H%M"
/usr/local/bin/exiftool -P -overwrite_original -alldates="${dt01}" "$file"
touch -t "${dt02}" "$file"
done
done
echo "finish!"
これで、うるう年も対応できる。