0
votes

I have to make a script to copy a folder and it's subfolders from one directory into another directory which has hundreds of folders with different name.

The folder structure is similar to below:

Source (Directory M:)

Folder1
--------Subfolder1
--------Subfolder2
--------Subfolder3

Destination (Directory O:)

Folder A
--------SubfolderA

Folder B
--------SubfolderA

Folder C
--------SubfolderA

...

Folder xxx
--------SubfolderA

So far I made it up to this stage but can't get it working.

First I run this piece of code to get the list of folders in the destination directory and export it to a text file

dir /b /ad > c:\temp\folder-list.txt

Now I need to tell the script to copy the folder/subfolders from source to destination but I can't get it working.

 FOR  %%i in (c:\temp\folder-list.txt) DO xcopy /t /e M:\Folder1 %%i\SubfolderA\

Please help.

PS: Script should copy a folder to other folders which have random names.

I think, I'm making some progress here:

for /d %%a in ("O:\*") do if exist "%%a" xcopy /t /e "M:\Folder1" %%a\SubfolderA

but I'm getting the error below.

Invalid number of parameters

1
What happens? Does it not copy? - user6250760
The issue is, I don't know how to point the xcopy to the destination folders. I mean the O:\destination folders\SubfolderA - user2444190
What is the expected result? Where should Folder1 and Subfolder1 end up? - Florian Straub
Since the destination directory includes hundreds of folders with different names. The folder1 and all of it's subfolders should be copied into all the SubfolderA's in destination directory. - user2444190
NeĆ­ther from your descriptipn/code nor from the layout it's clear what you want to copy where. And it does look like a question for Super User not Stack Overflow - user6811411

1 Answers

0
votes

Here is the code that worked for me:

for /d %%a in ("O:\*") do if exist "%%a" xcopy /t /e "M:\Folder1\*" "%%a\SubfolderA"