How to copy one folder to all other subfolders of a folder?

天大地大妈咪最大 提交于 2019-12-12 03:07:37

问题


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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!