Reputation: 106
For example I have a folder structure like below
Parent
|--------|-------|-------|-------|
Fol1 Fol2 Fol3 Fol4 Fol5
| | | | |
Sub1 Sub2 Sub3 Sub4 Sub5
| | | | |
File1 File2 File3 File4 File5
How can I copy the contents and of the subdirectories of the Parent folder to a New Directory. I want the structure to be like this:
New Directory
|-------|-------|-------|-------|
Sub1 Sub2 Sub3 Sub4 Sub5
| | | | |
File1 File2 File3 File4 File5
Upvotes: 2
Views: 94
Reputation: 6620
Try this:
@echo off
set parent=C:\Path\To\Parent\
set target=C:\Path\To\New Directory\
cd "%parent%"
for /d %%a in (*) do (
pushd "%%~a"
for /d %%b in (*) do (
md "%target%\%%~b"
copy "%%~b\*" "%target%\%%~b\"
)
popd
)
And that should do what you want it to. Note it hasn't been tested yet.
Upvotes: 0
Reputation: 41297
Test this:
@echo off
cd /d "parent"
for /d %%a in (*) do xcopy "%%a\*.*" "d:\new directory\" /s/h/e/k/f/c
Upvotes: 4