find $P -type f -print0 | xargs -0 ls -tr | while read file; do
N=$((N+1))
new=$( printf "%05d.%s" $N "${file##*.}" )
mv "$file" "$new"
done
find $P -type f -print0 | xargs -0 ls -tr | while read file; do
N=$((N+1))
new=$( printf "%05d.%s" $N "${file##*.}" )
mv "$file" "$new"
done