JayMel
JayMel

Reputation: 21

Search all subfolders for a foldername that has a specific string

I need a batch file that will search all subfolders in a folder, find any folder named Reports (there will be many and file paths will be changing constantly) and then copy the reports folders contents (not the folder) back to a root directory for export. For example: I have a folder on my desktop called Cases. I need to search all sub folders for folders called Reports and then copy those files out.

Any help would be appreciated.

Upvotes: 1

Views: 690

Answers (1)

double-beep
double-beep

Reputation: 5504

Here is a way you can do it (assuming you are talking about Cases folder in your desktop [in cmd]):

for /R "%userprofile%\Desktop\Cases" /D %A in (Reports.?) do @xcopy /s %~fA full_path_you_want

For batch file you should double the percent-signs (%%) just like this:

@echo off
for /R "%userprofile%\Desktop\Cases" /D %%A in (Reports.?) do xcopy /s %%~fA full_path_you_want

To learn more about commands and wildcards (.?) you can:

Hope this helps!

Upvotes: 1

Related Questions