See also: Heapify

Back to doug's directory

File information
Filename: renameJPEG.sh Uploaded: Sun, 2nd Jan 2011 00:59:08
Size (bytes): 977 bytes md5 checksum: 39955f592ced712eca05a91c145d25a3
Uploader doug Download: renameJPEG.sh
Description:

Batch rename JPEG files by their exposure date.

#!/bin/bash
 
rm renameJPEG.restore.sh
 
for file in *.jpg *.jpeg *.JPG *.JPEG; do
        if [ ! -e "$file" ]; then
                continue
        fi
        echo "Inspecting $file"
        DateTime=`jhead "$file" | grep "Date/Time"`
        FoundCount=`jhead "$file" | grep "Date/Time" | wc -l`
        if [ $FoundCount -gt 1 ]; then
                echo "Found too many results for: $file"
                continue
        elif [ $FoundCount -eq 0 ]; then
                echo "No valid headers found."
                continue
        else
            BaseFile=`echo $DateTime | awk '{ print $3 }' | tr ':' '-'`
            for i in `seq 1000`; do
                if [ ! -e "$BaseFile - $i.jpg" ]; then
                    echo "New file: $BaseFile - $i.jpg"
                    mv "$file" "$BaseFile - $i.jpg"
                    echo "mv '$BaseFile - $i.jpg' '$file'" >> renameJPEG.restore.sh
                    break
                fi
            done
        fi
done
 
RSS
Powered by Debian, Guinness, and excessive quantities of caffeine and sugar.