だから基本的に私は古い写真がたくさんある外付けハードドライブを持っていて、私の目標はそれらの写真をすべてGoogleフォトに保存することです。問題は、写真がMacフォトソフトウェアを使用して管理され、年と日付に基づいて複数のフォルダに分類されるため(およそ4000の異なるフォルダであると考えています)、写真を手動で参照してアップロードできますが、時間がかかりますです。そのため、画像拡張子(.jpg、.bmpなど)を含むすべてのファイルをインポートしてフォルダに移動する方法を探しています。私はUbuntuを使用しており、これを達成するためにスクリプトを書くことを恐れていません。ありがとうございます!
ベストアンサー1
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
これにより、写真の解像度に応じて写真が整理され、動画は動画に保存され、その他の無視されたファイルはその他/