将目录(和子目录)中的每个 PDF 文件移动到另一个文件夹

发布于 2024-10-19 17:58:32 字数 451 浏览 7 评论 0原文

我想将文件夹及其子文件夹内的每个 .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 脚本做同样的事情吗?

I want to move every single .pdf file inside a folder an its subfolders to another folder. I'm trying to do this with AppleScript, but an error is returned:

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

Does anyone know how to solve it?

Also, is there any way to do the same with shell script?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

滥情稳全场 2024-10-26 17:58:32

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

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

The following will search recursively and move all the *.pdf files to another folder.

find /your/folder -name "*.pdf" -exec mv {} /your/other/folder \;
心的憧憬 2024-10-26 17:58:32

使用 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/ \;

Using the CLI, rsync is an excellent option. Given this structure:

$ 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

This will transfer all PDF's and directories, excluding all other files:

$ 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/

If you don't care about maintaing the folder structure:

find src/ -name "*.pdf" -exec mv {} dest/ \;
潜移默化 2024-10-26 17:58:32

这是一个 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

Here's an applescript method. Using "entire contents" in the command makes it also search subfolders.

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文