Ant:复制相对文件列表的最简单方法

时间:2010-06-11 15:11:43

标签: ant copy

使用Ant,我想将一个文件列表从一个项目复制到另一个项目,其中每个项目都有相同的目录结构。有没有办法让以下工作?

<project name="WordSlug" default="pull" basedir=".">

  <description>
      WordSlug: pull needed files
  </description>

  <property name="prontiso_home" location="../../prontiso/trunk"/>

  <!-- I know this doesn't work, what's the missing piece? -->
  <target name="pull" description="Pull needed files">
      <copy todir="." overwrite="true">
        <resources>
          <file file="${prontiso_home}/application/views/scripts/error/error.phtml"/>
          <file file="${prontiso_home}/application/controllers/CacheController.php"/>
          <!-- etc. -->
        </resources>
      </copy>
  </target>

</project>

成功是自动导出路径:

${prontiso_home}/application/views/scripts/error/error.phtml copied to ./application/views/scripts/error/error.phtml
${prontiso_home}/application/controllers/CacheController.php copied to ./application/controllers/CacheController.php

谢谢!

2 个答案:

答案 0 :(得分:2)

尝试创建文件集:

<copy todir="." overwrite="true">
    <fileset dir="${prontiso_home}/application/">
        <include name="views/scripts/error/error.phtml,controllers/CacheController.php"/>
    </fileset>
</copy>

但是,通常使用fileset来定义要复制的文件的模式,例如“复制我的应用程序目录中的所有PHP文件:

    <fileset dir="${prontiso_home}/application/">
        <include name="**/*.phtml,**/*.php"/>
    </fileset>

答案 1 :(得分:0)

OP在这里。我有一个有效的解决方案:

<project name="WordSlug" default="pull" basedir=".">

  <description>
      WordSlug: pull needed files
  </description>

  <property name="prontiso_home" location="../../prontiso/trunk"/>

  <target name="pull" description="Pull needed files">
      <copy todir="." overwrite="true" verbose="true">
        <fileset dir="${prontiso_home}">
          <or>
            <filename name="/application/views/scripts/error/error.phtml"/>
            <filename name="/application/controllers/CacheController.php"/>
          </or>
        </fileset>
      </copy>
  </target>

</project>