How can I recursively copy files of a specific pattern into a single flat folder on Windows?

前端 未结 6 1215
别跟我提以往
别跟我提以往 2020-12-04 09:47

I need to copy a set of DLL and PDB files from a set of folders recursively into another folder. I don\'t want to recreate the folder hierarchy in the target folder. I wan

相关标签:
6条回答
  • Make sure that you have the quotes right if you have spaces in your path.

    This is my postbuild event for my TFS build server (that is why there is "%%"). I needed all the test files to be copied over.

    if not exist  "$(TargetDir)..\SingleFolderOutput" mkdir -p "$(TargetDir)..\SingleFolderOutput"
    
    for /r **%%x** in (*.dll, *.pdb, *.xml, *.xaml, *.exe, *.exe.config) do xcopy **"%%x"** "$(TargetDir)..\SingleFolderOutput" /Y
    
    0 讨论(0)
  • 2020-12-04 10:12

    command XCOPY

    example of copying folder recursively:

    mkdir DestFolder
    xcopy SrcFolder DestFolder /E
    

    (as stated below in the comment following WIKI that command was made available since DOS 3.2)

    0 讨论(0)
  • 2020-12-04 10:16

    For gathering PBD files I end up with this:

    cmd /q /c for /R "<your_source_folder>" %f in (*.pdb) do xcopy "%f" "<your_destination_folder>" /I /Y
    
    0 讨论(0)
  • 2020-12-04 10:18

    I'm not aware of any command line tools that do this directly, but you could create a batch script to loop through sub folders, and copy the files you need.

    However you may end up with files with duplicate filenames if you place them all in the same folder.

    0 讨论(0)
  • 2020-12-04 10:19
    @echo off
    if %1'==' goto usage
    if %2'==' goto usage
    if %3'==' goto usage
    for /D %%F in (%1\*) do xcopy %%F\%2 %3 /D /Y
    for /D %%F in (%1\*.) do call TreeCopy %%F %2 %3
    goto end
    :usage
    @echo Usage: TreeCopy [Source folder] [Search pattern] [Destination folder]
    @echo Example: TreeCopy C:\Project\UDI *.xsd C:\Project\UDI\SOA\Deploy\Metadata
    :end
    
    0 讨论(0)
  • 2020-12-04 10:23
    mkdir targetDir
    for /r %x in (*.dll, *pdb) do copy "%x" targetDir\
    

    Use /Y at the end of the above command if you are copying multiple files and don't want to keep answering "Yes".

    0 讨论(0)
提交回复
热议问题