2017-01-08 4 views
0

맥 사진에서 내 사진을 합당한 날짜 & 시간대의 폴더 구조와 파일 이름으로 백업하거나 다른 프로그램에서 사용할 수 있도록 백업하려고합니다. 파인더를 통해 파일. Stackoverflow 덕분에 당신은 도서관에서 Master 폴더를 복사 한 다음 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" 

이 년, 월, 시간으로 분류 폴더/이름 구조로 모든 사진을 넣어 사진의 생성 날짜를 사용하여 계산합니다. 또한 원본을 제거합니다.

필자는 다년간의 사진을 정리하고 새 사진을 계속 가져올 때 이것을 사용합니다. 생성 날짜가 존재하지 않으면 파일을 건너 뜁니다.