本文介绍了复制多个目录(和内容)一炮打响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用蚂蚁了近十年,但每隔一段时间,我需要做一些超出我一般的体验。这其中缺乏一个明显的答案(和直观的方式导致死角)

I've been using ant for nearly a decade, but every so often I need to do something beyond my-ordinary experience. This one lacked an obvious answer (and the intuitive approaches led to dead ends)

问题:

复制几个子目录(及其内容)目录榜样新目录将myInstance。为了澄清,复制了一些,但在源目录并非所有子目录。

Copy several subdirectories (and their contents) in directory "example" to new directory "myInstance". To clarify, copy some, but not all subdirectories in the source directory.

源目录:

example/
  ignoreThisDirectory/
  ignoreThisOneAlso/
  lib
  etc/
  webapps/

尝试:穷途末路
这种尝试在第一次出现工作。它创建子目录LIB等,web应用。但是复制并没有复制它们的内容;我留下了空的子目录。

Attempt: Dead EndThis attempt at first appeared to work. It created the subdirectories lib, etc,webapps. However 'copy' did not copy their contents; i was left with empty subdirectories.

<copy todir="myInstance" >
  <dirset dir="example" includes="lib etc webapps"/>      
</copy>    

成功的,但详细
最后,我不得不每个目录逐个复制,这似乎冗长和非干:

Successful But VerboseIn the end, I had to copy each directory individually, which seem verbose and non-DRY:

   <copy todir="myInstance/etc">
     <fileset dir="example/etc"/>
    </copy>    
   <copy todir="myInstance/lib">
     <fileset dir="example/lib" />
    </copy>    
   <copy todir="myInstance/webapps">
     <fileset dir="example/webapps" />
    </copy>    

在此先感谢

推荐答案

您可以指定文件集多种包括和排除规则。如果没有指定包含规则,默认的是一切都包括在内,但任何被排除规则排除至少一次。

You can specify multiple inclusion and exclusion rules in a fileset. If you don't specify an inclusion rule, the default is everything is included, except anything that is excluded at least once by an exclude rule.

下面是一个包容性的例子:

Here's an inclusive example:

<property name="src.dir" value="example" />
<property name="dest.dir" value="myInstance" />

<copy todir="${dest.dir}">
    <fileset dir="${src.dir}">
        <include name="lib/**" />
        <include name="etc/**" />
        <include name="webapps/**" />
    </fileset>
</copy>

请注意在 ** 通配符,将在完整目录树带来下每三个'前沿'指定的子目录。另外,如果您想特别排除了一些目录,但复制于其他所有,你可能会忽略包容(从而得到默认的包容一切的行为),并提供排除名单:

Note the ** wildcard that will bring in the full directory tree under each of the three 'leading-edge' sub-directories specified. Alternatively, if you want to specifically exclude a few directories, but copy over all others, you might omit inclusion (and thereby get the default all-inclusive behaviour) and supply a list of exclusions:

<copy todir="${dest.dir}">
    <fileset dir="${src.dir}">
        <exclude name="ignoreThisDir*/" />
        <exclude name="ignoreThisOne*/" />
    </fileset>
</copy>

您可能会进一步煮你给下一个排除模式的具体示例:

You could further boil the particular example you gave down to one exclusion pattern:

<exclude name="ignore*/" />

这篇关于复制多个目录(和内容)一炮打响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 09:17