Solved copy multiple files in multiple folders to one folder

June 8, 2012 at 12:57:45
Specs: Windows 64
I want to copy files from multiple directories without creating the directory tree. XCOPY /S gets all the files I need, but creates the tree as well. I have more than 500 subdirectories and every folder contains files and other subdirectories. I want to copy all of the files from every subdirectory in main folder: "d:\temp1" into a new folder named d:\temp2 without creating the directory tree. Is there a way to do this without having to create a batch file containing a copy command for every folder?

See More: copy multiple files in multiple folders to one folder

Report •


#1
June 8, 2012 at 16:20:55
From command line:
FOR /R "d:\temp1" %A IN (*.*) DO COPY /Y "%~A" "d:\temp2\"

From batch:

FOR /R "d:\temp1" %%A IN (*.*) DO COPY /Y "%%~A" "d:\temp2\"

Assumption: you want to overwrite any/all existing files. If not, remove "/Y" switch, and answer each duplicate file prompt:

Overwrite d:\temp2\<duplicate file name>? (Yes/No/All):

When your only tool is a hammer, every problem looks like a nail.


Report •

#2
June 9, 2012 at 00:23:19
with the best wishes and much much thanks,,,,,
i have other problem in this case, i have Space in folder's name and files' name so these files have not been copied. what can i do?

Report •

#3
June 9, 2012 at 04:39:39
✔ Best Answer
i have other problem in this case, i have Space in folder's name and files' name so these files have not been copied. what can i do?

Ensure you are including the quotes surrounding the "A" variable and destination folder:

DO COPY /Y "%~A" "d:\temp2\"

and/or
DO COPY /Y "%%~A" "d:\temp2\"

The testing I have done correctly accounts for embedded spaces in both folders and file names.

When your only tool is a hammer, every problem looks like a nail.


Report •

Related Solutions

#4
June 9, 2012 at 21:37:08
it works! thanks thanks thanks, it's a perfect command. so many thanks Mr. ORANGEBOY

Report •


Ask Question