2017-01-08 7 views
0

Mac写真から46kの写真を妥当な日付にバックアップしようとしています&時間ベースのフォルダ構造とファイル名を別のプログラムで使用したり、ファインダーを介してファイル。 Stackoverflowとあなたの助けを借りて、私はライブラリからマスターフォルダをコピーしてからmvコマンドでそのフォルダのスクリプトを実行することでこれを行うことができました。私は残念なことに、適切な解決策を見つけ出したいと思います。私は、コードはライブラリ内のすべてのファイルが見つからないとエラーに遭遇し写真ライブラリのループトラフファイルが見つかりません

:助けを必要

  • スペースとドットが問題ではない、「/ユーザ/月/デスクトップでそれをテストしました/写真xy "
  • mdfindは端末のlibaryの写真に働きます
  • mdfindは/ Users/Jan/Pで実行すると170kファイルを見つけますしかし、それは図書館の元の画像だけをコピーするのではなく、

ありがとうございました!

#!/bin/bash 
#ensure no errors with spaces in filenames 
SAVEIFS=$IFS 
IFS=$(echo -en "\n\b") 
#define variables to count files and progress 
x=0 
y=0 
#count files in Master (Original Pictures) directory 
for file in `mdfind file -onlyin "/Users/Jan/Pictures/Photos Library.photoslibrary/Masters"` 
do 
    x=$((x+1)) 
done 
echo "$x files found" 
#loop for all files in Master (Original Pictures) directory 
for file in `mdfind file -onlyin "/Users/Jan/Pictures/Photos Library.photoslibrary/Masters"` 
do 
    #get date and timestamp of creation date and define Year, Month, Day, Hour, Minute & Second as variable for the filename 
    D=$(mdls "$file" | grep ContentCreationDate | awk '{print $3, $4}') 
    YYYY=$(echo $D| cut -c 1-4) 
    MM=$(echo $D| cut -c 6-7) 
    DD=$(echo $D| cut -c 9-10) 
    H=$(echo $D| cut -c 12-13) 
    M=$(echo $D| cut -c 15-16) 
    S=$(echo $D| cut -c 18-19) 
    #add a variable in case multiple files with same timestamp exist 
    i=1 
    #define path and create new folders if required: "One per month in every year" 
    newdir=$(echo /Users/Jan/Desktop/Photos/Sorted/$YYYY/$MM/) 
    mkdir -p $newdir 
    #get file extension 
    ext=$(echo "$file"|awk -F . '{print $NF}') 
    #define path and name of new file 
    newfile=$(echo $newdir$YYYY-$MM-$DD_$H-$M-$S.$ext) 
    #add a loop to add variable i and increase i in case a file with the same timestamp already exists 
    while test -f "$newfile" 
     do newfile=$(echo $newdir$YYYY-$MM-$DD_$H-$M-$S_$i.$ext) 
     i=$((i+1)) 
    done 
    #copy file into new directory with new timestamp name 
    cp -p "$file" "$newfile" 
    y=$((y+1)) 
    echo "$y out of $x files completed" 
done 
exit 
+0

エラーメッセージはありますか?デバッグモード( '-x')でスクリプトを実行しようとしましたか? – Jdamian

+0

'$(echo ...)'を使う必要はないのですか?: 'newfile =" $ newdir $ YYYY- $ MM- $ DD_ $ H- $ M- $ S. $ ext "' – Jdamian

答えて

0

exiftoolとお考えですか?

exiftool -r -P -d "/path/to/new/folder/%Y/%m/img_%Y%m%d_%H%M%S%%-c.%%e" "-filename<createdate" "/path/to/existing/pictures" 

これは、写真の作成日を使用して、年、月、時間、およびカウントで区切られたフォルダ/命名構造にすべての画像を置きます。また、オリジナルを削除します。

私は何年もの写真を整理し、新しいものを引き続き取り込むときにこれを使用します。作成日が存在しない場合は、ファイルをスキップします。

関連する問題