Search code examples
windowsbatch-filecmdxcopy

Copy files from different folders


exists some way, how to copy files from different folders, when I don't know names of it?

Imagine that I have following folders and files

C:
  Build
    Tests
      DomainA.UnitTests
        bin
          domainA.dll
        src
          ...
      DomainA.IntegrationTests
        bin
          domainA.dll
        src
          ...
      DomainB.UnitTests
        bin
          domainB.dll
        src
          ...

For example in linux I can write command which copy files domainA.dll and domainB.dll:

cp -u Tests/*.UnitTests/bin/*.* Artifacts/Tests/UnitTests

and I need to write command/script with same behavior in windows command.

Thanks!


Solution

  • At a command line, I'd probably use for, which is basically how you always do everything non-trivial with cmd:

    for /d %d in (.\Tests\*.UnitTests) do (
        pushd %d\bin
        copy *.* ..\..\..\Artifacts\Tests\UnitTests
        popd
    )
    

    (Remember to use %%d in a batch file.)