Friday, February 20, 2015

Bash script for Cygwin to read in camera images from SD card

#this script does a nice job of reading in DCIM cards
#run with ./get_picts title
#it creates a folder with a date if the name is defaulted, appends drive name, then title.


#!/bin/bash
thisTitle=$*
getlabel() {
$(cygpath --sysdir)/cmd /c dir ${1}:\\ | \
    tr \\r \\n | \
    sed -n -e '1s/^ Volume in drive . is //p'
}

cd /cygdrive/c/DCIM
cd ~/DCIM
for i in e f g h i j k l m
#
#DIRS=`ls -d /media/matt/*/DCIM`
#echo $DIRS
#for thisTarget in $DIRS
do

    thisTarget="/cygdrive/${i}/DCIM"
    if [ -d "$thisTarget" ]; then
        driveName=`getlabel ${i}`
        echo  $driveName
        thisDate=$(date +%y%m%d)
        #echo $thisDate
        #echo $thisTitle
        thisDate=$thisDate"_"$driveName"_"$thisTitle
        echo $thisDate
        #read -p "Press [Enter] key to start copy..."

        if [ -d "$thisTarget/101ND610" ]; then
            mv "$thisTarget/101ND610" "$thisTarget/$thisDate"
        fi
        if [ -d "$thisTarget/101D3200" ]; then
            mv "$thisTarget/101D3200" "$thisTarget/$thisDate"
        fi
        if [ -d "$thisTarget/100D3200" ]; then
            mv "$thisTarget/100D3200" "$thisTarget/$thisDate"
        fi
        mv -f $thisTarget/1* .
        for jj in $(ls -d $thisTarget/* | xargs -n1 basename)
        do
            for kk in _1 _2 _3 _4 _5 _6 _7 _8
            do
                if [ -d $jj$kk ]; then
                    echo $jj$kk
                else
                    mv -f $thisTarget/$jj  $jj$kk   
                    break
                fi
            done
        done
        rmdir $thisTarget
    fi
done
find . -type d -exec rmdir --ignore-fail-on-non-empty -p {} \;
find . -name "DSC*.JPG" -ls -exec exifautotran {} \;
find . -name "IMG*.JPG" -ls -exec exifautotran {} \;
find . -name "DSC*.JPG" -ls -exec exiftool  -d %Y.%m.%d-%H.%M.%S%%-c '-filename<$CreateDate-$filenumber.%e' {} \;
find . -name "DSC*.NEF" -ls -exec exiftool  -d %Y.%m.%d-%H.%M.%S%%-c '-filename<$CreateDate-$filenumber.%e' {} \;
find . -name "IMG*.PEF" -ls -exec exiftool  -d %Y.%m.%d-%H.%M.%S%%-c '-filename<$CreateDate-$filenumber.%e' {} \;
find . -name "IMG*.PEF" -ls -exec exiftool  -d %Y.%m.%d-%H.%M.%S%%f%%-c '-filename<$CreateDate.%e' {} \;
find . -name "IMG*.CR2" -ls -exec exiftool  -d %Y.%m.%d-%H.%M.%S%%-c '-filename<$CreateDate-$filenumber.%e' {} \;
find . -name "IMG*.DNG" -ls -exec exiftool  -d %Y.%m.%d-%H.%M.%S%%-c '-filename<$CreateDate-$filenumber.%e' {} \;
find . -name "IMG*.DNG" -ls -exec exiftool  -d %Y.%m.%d-%H.%M.%S%%f%%-c '-filename<$CreateDate.%e' {} \;
find . -name "IMG*.JPG" -ls -exec exiftool  -d %Y.%m.%d-%H.%M.%S%%-c '-filename<$CreateDate-$filenumber.%e' {} \;
find . -name "IMG*.JPG" -ls -exec exiftool  -d %Y.%m.%d-%H.%M.%S%%f%%-c '-filename<$CreateDate.%e' {} \;
find . -name   "P*.JPG" -ls -exec exiftool  -d %Y.%m.%d-%H.%M.%S%%-c '-filename<$CreateDate-$filenumber.%e' {} \;
find . -name   "P*.JPG" -ls -exec exiftool  -d %Y.%m.%d-%H.%M.%S%%f%%-c '-filename<$CreateDate.%e' {} \;




No comments:

Post a Comment