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

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

    Under Linux and other UNIX systems, using the tar command would do this easily.

    $ tar cvf /tmp/full-structure.tar *data.zip *info.txt
    

    Then you'd cwd to the target and:

    $ tar xvf /tmp/full-structure.tar 
    

    Of course you could pipe the output from the first tar into the 2nd, but seeing it work in steps is easier to understand and explain. I'm missing the necessary cd /to/new/path/ in the following command - I just don't recall how to do it now. Someone else can add it, hopefully.

    $ tar cvf -  *data.zip *info.txt |  tar xvf - 
    

    Tar (gnutar) is available on Windows too, but I'd probably use the xcopy method myself on that platform.

提交回复
热议问题