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

前端 未结 15 1682
半阙折子戏
半阙折子戏 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:29

    For those using Altap Salamander (2 panels file manager) : in the Options of the Copy popup, just specify the file names or masks. Easy.

    0 讨论(0)
  • 2020-12-07 08:30
    XCOPY /S folder1\data.zip copy_of_folder1  
    XCOPY /S folder1\info.txt copy_of_folder1
    

    EDIT: If you want to preserve the empty folders (which, on rereading your post, you seem to) use /E instead of /S.

    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题