0

So basically I have an external hard drive with a bunch of old pictures on it my goal is to get them all to google photos. Problem is since these photos where managed with the mac photo software there sorted into a whole bunch of different folders depending on year and date(I think there's about 4000 different folders) I could go through and upload the photos by hand but that would take a long time. So I'm looking for a way to grab all the files with a picture extension ex .jpg, .bmp, and etc and move them to a folder. I'm using Ubuntu and am not afraid to write a script to achieve this. Thank you!

1 Answers1

0
function imageext () 
{ 
    if ! ((${#imageextensionlist[@]})); then
        declare -ga imageextensionlist=($(grep / /etc/mime.types|grep 'image/'|xargs printf '%s\n'|grep -v /));
    fi;
    [[ " ${imageextensionlist[@]} " == *" ${1,,} "* ]]
}
function videoext () 
{ 
    if ! ((${#videoextensionlist[@]})); then
        declare -ga videoextensionlist=($(grep / /etc/mime.types|grep 'video/'|xargs printf '%s\n'|grep -v /));
    fi;
    [[ " ${videoextensionlist[@]} " == *" ${1,,} "* ]]
}
function imagesize () # you may need to install imagemagick
{ 
    local re=$(identify -format %wx%h "${1}");
    printf "${re%%x*}x${re##*x}"
}

cd /parrent/dir/where/your/pictures;
mkdir tmp;
mv * tmp/;
mkdir videos pictures other;


find "${PWD}/tmp" -type f | while read thefile;do
    if imageext "${thefile##*.}";then
        imgsize="$(imagesize "${thefile}")";
        [[ ! -d "${imgsize:-none}" ]] && mkdir -p "${imgsize:-none}"
        mv "${thefile}" pictures/${imgsize:-none}/;
    elif videoext "${thefile##*.}";then
        mv "${thefile}" videos/;
    else
        mv "${thefile}" other/
    fi
done

this will organize pictures by resolution inside pictures/ and puts videos inside videos/ and other ignored files inside other/

Yunus
  • 1,684