如何复制目录结构,但只包括某些文件(使用窗口批处理文件) [英] How to copy a directory structure but only include certain files (using windows batch files)

查看:291
本文介绍了如何复制目录结构,但只包括某些文件(使用窗口批处理文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所说,我怎么可以递归复制目录结构,但只包含一些文件。例如考虑到以下目录结构:

 文件夹1
  文件夹2
    folder3
      data.zip
      信息.txt
      abc.xyz
    folder4
    folder5
      data.zip
      somefile.exe
      someotherfile.dll

该文件的 data.zip 信息.txt 随处在目录结构中出现。我怎么能复制完整的目录结构,但只包含文件名为data.zip和信息.txt(所有其他文件应该被忽略)?

生成的目录结构应该是这样的:

  copy_of_folder1
  文件夹2
    folder3
      data.zip
      信息.txt
    folder4
    folder5
      data.zip


解决方案

您没有提到是否具有只批,但如果你可以使用 ROBOCOPY ,试试这个:

  ROBOCOPY C:\\来源C:\\目的地data.zip信息.txt / E

编辑:改变了 / S 参数 / E 来包括空文件夹

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
  folder2
    folder3
      data.zip
      info.txt
      abc.xyz
    folder4
    folder5
      data.zip
      somefile.exe
      someotherfile.dll

The files data.zip and info.txt can appear everywhere in the directory structure. How can I copy the full directory structure, but only include files named data.zip and info.txt (all other files should be ignored)?

The resulting directory structure should look like this:

copy_of_folder1
  folder2
    folder3
      data.zip
      info.txt
    folder4
    folder5
      data.zip

解决方案

You don't mention if it has to be batch only, but if you can use ROBOCOPY, try this:

ROBOCOPY C:\Source C:\Destination data.zip info.txt /E

EDIT: Changed the /S parameter to /E to include empty folders.

这篇关于如何复制目录结构,但只包括某些文件(使用窗口批处理文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆