【问题标题】:Move every PDF file inside directory (and subdirectory) to another folder将目录(和子目录)内的每个 PDF 文件移动到另一个文件夹
【发布时间】:2011-07-07 14:04:28
【问题描述】:

我想将文件夹中的每个 .pdf 文件及其子文件夹移动到另一个文件夹。我正在尝试使用 AppleScript 执行此操作,但返回错误:

tell application "Finder"
    set theFolder to path to downloads folder from user domain
    set destFolder to choose folder
    repeat with currentFolder in (every folder of theFolder)
        move (every item of (currentFolder) that name extension is "pdf") to destFolder
    end repeat
end tell

有人知道怎么解决吗?

另外,有什么方法可以用 shell 脚本做同样的事情吗?

【问题讨论】:

    标签: bash shell applescript directory


    【解决方案1】:

    以下将递归搜索并将所有 *.pdf 文件移动到另一个文件夹。

    find /your/folder -name "*.pdf" -exec mv {} /your/other/folder \;
    

    【讨论】:

    • @Fabio: 你想同时镜像另一个文件夹中的目录树吗?
    • 那么,上面的方法现在对你有用吗(在模式周围加上引号)?
    【解决方案2】:

    使用 CLI,rsync 是一个很好的选择。鉴于这种结构:

    $ find src
    src
    src/1.pdf
    src/4.txt
    src/a
    src/a/2.pdf
    src/a/b
    src/a/b/3.pdf
    src/c
    src/c/5.txt
    

    这将传输所有 PDF 和目录,不包括所有其他文件:

    $ rsync -av --include="*.pdf" --include "*/" --exclude "*" src/ dest
    building file list ... done
    created directory dest
    ./
    1.pdf
    a/
    a/2.pdf
    a/b/
    a/b/3.pdf
    c/
    

    如果您不关心维护文件夹结构:

    find src/ -name "*.pdf" -exec mv {} dest/ \;
    

    【讨论】:

      【解决方案3】:

      这是一个applescript方法。在命令中使用“整个内容”使其还可以搜索子文件夹。

      set theFolder to path to downloads folder from user domain
      set destFolder to choose folder
      
      tell application "Finder"
          set thePDFs to files of entire contents of theFolder whose name extension is "pdf"
          move thePDFs to destFolder
      end tell
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-07-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-06-09
        • 1970-01-01
        • 2019-11-20
        相关资源
        最近更新 更多