Move every PDF file inside directory (and subdirectory) to another folder
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 t开发者_高级运维o 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?
The following will search recursively and move all the *.pdf files to another folder.
find /your/folder -name "*.pdf" -exec mv {} /your/other/folder \;
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/ \;
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
精彩评论