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

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

问题描述

正如标题所说,如何递归复制目录结构但只包含一些文件.例如,给定以下目录结构:

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

文件data.zipinfo.txt 可以出现在目录结构中的任何地方.如何复制完整的目录结构,但只包含名为 data.zip 和 info.txt 的文件(应忽略​​所有其他文件)?

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

推荐答案

你没有提到它是否必须只是批处理,但如果你可以使用 ROBOCOPY,试试这个:

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

/S 参数更改为 /E 以包含空文件夹.

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

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

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