简体   繁体   中英

Copy contents of subfolder to another folder

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

Test this:

@echo off
cd /d "parent"
for /d %%a in (*) do xcopy "%%a\*.*" "d:\new directory\" /s/h/e/k/f/c

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM