Bash 循环浏览照片库中的文件';我找不到任何文件

Bash 循环浏览照片库中的文件';我找不到任何文件,bash,macos,terminal,photo,Bash,Macos,Terminal,Photo,我正在尝试将我的46k照片从Mac Photos备份到一个合理的基于日期和时间的文件夹结构和文件名中,以便在其他程序中使用,或者通过finder轻松访问文件。多亏了StackOverflow的帮助,我成功地将主文件夹从库中复制出来,然后使用mv命令在该文件夹上运行脚本,我仍然面临挑战,希望找到一个合适的解决方案: 我遇到一个错误,代码在库中找不到任何文件: 空间和圆点不是问题,用“/Users/Jan/Desktop/Photos x.y”进行测试 mdfind适用于终端中的照片库 mdfin

我正在尝试将我的46k照片从Mac Photos备份到一个合理的基于日期和时间的文件夹结构和文件名中,以便在其他程序中使用,或者通过finder轻松访问文件。多亏了StackOverflow的帮助,我成功地将主文件夹从库中复制出来,然后使用mv命令在该文件夹上运行脚本,我仍然面临挑战,希望找到一个合适的解决方案:

我遇到一个错误,代码在库中找不到任何文件:

  • 空间和圆点不是问题,用“/Users/Jan/Desktop/Photos x.y”进行测试
  • mdfind适用于终端中的照片库
  • mdfind在/Users/Jan/Pictures上运行时会找到170k个文件,但是,这不仅会复制库中的原始图片
你考虑过使用吗


exiftool-r-P-d”/path/to/new/folder/%Y/%m/img\u%Y%m%d\u%H%m%S%%-c.%%e”“-filename是否有任何错误消息?是否尝试在调试模式下运行脚本(
-x
)?是否知道不必使用
$(echo··)
?:
newfile=“$newdir$yyyyyy-$MM-$DD\u$H-$m-$S.$ext”
#!/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
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"