#!/bin/bash
# サンヨーICレコーダーの録音ファイルの先頭3文字を録音順にナンバリング
# し直すスクリプト

ls ???????????????.MP3 >/dev/null 2>&1
if test $? -ne 0; then
echo "MP3 file not found."
exit
fi

set -e

ls -tr *.MP3|while read -r i
do
filename=${i:0:15}
mv $filename.MP3 tmp.$filename.MP3
set +e
mv $filename.INX tmp.$filename.INX
set -e
done


j=1
ls -tr *.MP3|while read -r i
do
filename=${i:0:19}
corename=${i:7:12}
num=$(printf "%03d" "$j")
set -x
mv ${filename}.MP3 $num${corename}.MP3
set +x
set +e
mv ${filename}.INX $num${corename}.INX
set -e
j=$((j+1))
done
