2011-03-02 140 views
1

我想将文件夹内的每个.pdf文件及其子文件夹移动到另一个文件夹。我试图用AppleScript来做到这一点,但错误返回:将目录(和子目录)中的每个PDF文件移动到另一个文件夹

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脚本来做同样的事情吗?

回答

1

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

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

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

error:'find:Calculus_Cheat_Sheet_All.pdf:unknown option' – 2011-03-02 20:47:38

+0

试试我的编辑。 – 2011-03-02 20:51:22

+0

@Fabio:你也想镜像其他文件夹中的目录树吗? – 2011-03-02 21:27:17

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/ \; 
相关问题