Ant——从树上的一个子目录复制文件和子目录 [英] Ant -- copying files and subdirectories from only one subdirectory on a tree

查看:56
本文介绍了Ant——从树上的一个子目录复制文件和子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Ant 从单个子目录复制文件和子目录,而不复制其余的目录结构和内容.例如,我想复制 dir_3、它的文件(file_1 到 file_n)和子目录(dir_4 和 dir_5),但不是 dir_1 和 dir_2.有没有一种模式可以用来做到这一点?

I'd like to copy files and subdirectories using Ant from a single subdirectory without copying the rest of the directory structure and contents. For example, I'd like to copy dir_3, its files (file_1 to file_n) and subdirectories (dir_4 and dir_5), but not dir_1 nor dir_2. Is there a pattern that I can use to do this?

temp
   \--dir_1
   \--dir_2
       |
       \--dir_3
           |
           \--dir_4
           \--dir_5
           \-- file_1
           |
           \--file_n

谢谢.

推荐答案

<copy todir="${copy.dir}">
     <fileset dir="temp">
         <include name="**/dir3/**"/>
     </fileset>
</copy>

当您使用 include 指令时,它只会包含与您提供的模式匹配的文件.在这种情况下,我只复制那些在其完整路径名中包含 /dir3/ 的文件.这包括 dir3 下的子目录和 dir3 下的所有文件.

When you use the include directive, it will only include the files that match the pattern you give it. In this case, I'm copying only those files that have /dir3/ somewhere in their full path name. This includes sub-directories under dir3 and all files under dir3.

您可以使用 exclude 指令覆盖 include 指令:

You can use the exclude directive to override the include directives:

<copy todir="${copy.dir}">
     <fileset dir="temp">
         <include name="**/dir3/**"/>
         <exclude name="**/dir3/*"/>
     </fileset>
</copy>

这将复制这些子目录中的所有子目录和文件,但不会复制 dir3 本身下的文件.* 匹配目录中的所有文件,而 ** 匹配整个目录树中的所有文件.

This will copy all sub-directories and files in those sub directories, but not the files under dir3 itself. The * matches all files in the directory while ** matches the all the files in the entire directory tree.

注意这将创建一个目录temp/dir2/dir3.如果我想要temp/dir3,我必须将我的文件集设置为dir3 的父目录:

Notice this will create a directory temp/dir2/dir3. If I want temp/dir3, I have to set my fileset to the parent directory of dir3:

<copy todir="${copy.dir}">
     <fileset dir="temp/dir2">
         <include name="dir3/**"/>
     </fileset>
</copy>

这样做:

<copy todir="${copy.dir}">
     <fileset dir="temp/dir2/dir3"/>
</copy>

将在 temp 下直接创建一个目录 temp,其中包含 dir3 下的所有文件.还将有一个 temp/dir4temp/dir5 目录,其中包含这些目录下的所有文件(和目录树).

Will create a directory temp with all the files directly under dir3 directly under temp. There will also be a temp/dir4 and temp/dir5 directory containing all the files (and directory trees) under those directories.

这篇关于Ant——从树上的一个子目录复制文件和子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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