问题
I want to copy folder IMAGE to all other folders in a folder.
The folder structure is:
- Test folder
- FirstSubFolder
- IMAGE
- OneMoreSubFolder
- Test Folder 1
- TestFolder2
The result should be:
- Test folder
- FirstSubFolder
- IMAGE
- IMAGE
- OneMoreSubFolder
- IMAGE
- Test Folder 1
- IMAGE
- TestFolder2
- IMAGE
- FirstSubFolder
Which commands do I need in a batch script to do this folder copying task?
回答1:
With Test folder being the current directory use following batch code:
@echo off
for /D %%D in (*) do (
if /I not "%%D" == "IMAGE" (
xcopy "IMAGE\*" "%%D\IMAGE\" /C /E /H /I /K /Q /R /Y >nul
)
)
Or if just the files and subfolders in IMAGE should be copied to all other subfolders of Test folder, use this code:
@echo off
for /D %%D in (*) do (
if /I not "%%D" == "IMAGE" (
xcopy "IMAGE\*" "%%D\" /C /E /H /I /K /Q /R /Y >nul
)
)
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
echo /?for /?if /?xcopy /?
来源:https://stackoverflow.com/questions/34207713/how-to-copy-one-folder-to-all-other-subfolders-of-a-folder