How to Copy All PDF Files from a Directory and Its Subdirectories to One Location

Copy All PDFs in a folder and all subfolders to a new folder using R

Using list.files you can get complete path of all the pdf files in the main folder as well as sub folders. Then use file.copy to copy all the pdf files to new folder (called New_folder here).

all_pdf <- list.files('main/folder', pattern = '\\.pdf$', recursive = TRUE, full.names = TRUE)
file.copy(all_pdf, 'New_folder/')

How to copy all files in the subfolder

Use the xcopy command. You can go to a command prompt and type xcopy /? to get help using it.

For your particular question, the full command would be:

xcopy c:\sourcefolder\*.pdf c:\destinationfolder\ /e

Move every PDF file inside directory (and subdirectory) to another folder

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

Copy pdfs in a directory to folders with the same name as the PDFs

You can use pathlib and shutil to perform this:

from pathlib import Path
from shutil import move

path_to_files = Path(r"C:\tmp\all_files_converted")
for pdf_path in path_to_files.glob("*.pdf"):
dir_path = path_to_files / pdf_path.stem
dir_path.mkdir()
move(pdf_path, dir_path / pdf_path.name)


Related Topics



Leave a reply



Submit