I have multiple project folders that contain files. The folders are named by their project id. I need to copy any pdf files that contain the word "approved" to a new folder. Below is an example.
Copy from here:
C:\Projects\Project_1\*Approved*.pdf
To here:
C:\Attachments\Project_1\Documents\*Approved*.pdf
The batch file needs to create a new project folder in "C:\Attachments" as well as 2 subfolders, "Documents" and "Images" and put the corresponding pdf files in the "Documents" folder.
I appreciate any help.
Batch file to create folder and subfolders and copy files
Moderator: DosItHelp
Re: Batch file to create folder and subfolders and copy file
Test this:
Code: Select all
@echo off
for /r "C:\Projects" %%a in ("*Approved*.pdf") do (
for %%b in ("%%~dpa\.") do (
echo processing "%%a"
md "C:\Attachments\%%~nxb\Documents" 2>nul
md "C:\Attachments\%%~nxb\Images" 2>nul
copy "%%a" "C:\Attachments\%%~nxb\Documents" >nul
)
)
pause
Re: Batch file to create folder and subfolders and copy file
That worked great! That's exactly what I needed. Thank you!
Re: Batch file to create folder and subfolders and copy file
I noticed that the batch file is copying all the files every time it is run. Could it be possible to only copy new or modified files?
Re: Batch file to create folder and subfolders and copy file
Figured out my last question. Am able to copy just new or modified files by using xcopy instead of copy and /s /d /y. Thanks!