How to copy a directory structure but only include certain files (using windows batch files)

前端 未结 15 1737
半阙折子戏
半阙折子戏 2020-12-07 07:50

As the title says, how can I recursively copy a directory structure but only include some files. E.g given the following directory structure:

folder1
  folde         


        
15条回答
  •  感动是毒
    2020-12-07 08:31

    Similar to Paulius' solution, but the files you don't care about are not copied then deleted:

    @echo OFF
    
    :: Replace c:\temp with the directory where folder1 resides.
    cd c:\temp
    
    :: You can make this more generic by passing in args for the source and destination folders.
    for /f "usebackq" %%I in (`dir /b /s /a:-d folder1`) do @echo %%~nxI | find /V "data.zip" | find /v "info.txt" >> exclude_list.txt
    xcopy folder1 copy_of_folder1 /EXCLUDE:exclude_list.txt /E /I
    

提交回复
热议问题