0

I need to batch copy two folders, let's call them A and B, from F:\Sourcefolder\ to F:\destinationfolder subfolders (not to destination folder itself).

Now I know when batch copying file (file.exe for example) it is supposed to look something like this

for /r "F:\destinationfolder" %%i in (.) do @copy "F:\Sourcefolder\file.exe" "%i"

In each of those subfolders there is a lot of files. After copying A and B folders to all subfolders, I would like to move all files within the subfolders to folder A within their folder. Is this possible to do?

1 Answers1

0

the XCOPY command is designed for folder copy, FOR /D will list level1 folders:

for /d %%a in ("F:\destinationfolder\*") do (
    XCOPY "F:\Sourcefolder\A\*" "%%~fa" /s /i
    XCOPY "F:\Sourcefolder\B\*" "%%~fa" /s /i
)

for recursive copy (all subfolders):

for /r /d "F:\destinationfolder\" %%a in (*) do (
    XCOPY "F:\Sourcefolder\A\*" "%%~fa" /s /i
    XCOPY "F:\Sourcefolder\B\*" "%%~fa" /s /i
)

FOR /R will not work properly if there's no wildcard in the brackets - ? or *

ROBOCOPY,XCOPY

npocmaka
  • 55,367
  • 18
  • 148
  • 187