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

查看:260
本文介绍了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下.还有一个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天全站免登陆