开发者

How do I use Ant to copy a folder?

I'm trying to copy a directory using the Ant copy task.

I am a newbie at Ant; my current solution is:

<copy todir="${release_dir}/lib">
   <fileset dir="${libpath}" />
</copy>

I'm wonde开发者_运维知识库ring if there is a better and shorter way to accomplish the same thing?


First of all, those are the examples from Ant documentation:

Copy a directory to another directory

<copy todir="../new/dir">
  <fileset dir="src_dir"/>   
</copy>

Copy a set of files to a directory

<copy todir="../dest/dir">
  <fileset dir="src_dir">
    <exclude name="**/*.java"/>
  </fileset>
</copy>

<copy todir="../dest/dir">
  <fileset dir="src_dir" excludes="**/*.java"/>   
</copy>

Copy a set of files to a directory, appending .bak to the file name on the fly

<copy todir="../backup/dir">
  <fileset dir="src_dir"/>
  <globmapper from="*" to="*.bak"/>   
</copy>

Secondly, here is the whole documentation about copy task.


Just because the docs were not very clear to me, and because the time I spent can serve others:

The docs say that this "copies a directory (dir1) to another directory (dest)":

<copy todir="../new/dest">
  <fileset dir="src/dir1"/>   
</copy>

Actually, this does not mean "copy dir1 inside dest", but rather "copy the contents of dir1 inside dest".

(In general, in Ant, the "root dir" of a filesets -as well at the todir attribute- is not considered as being part of the set itself.)

To place the directory dir1 inside dest one has several alternatives (none totally satisfying to me - and I'd imagined that the new DirSet would help here, but no)

<copy todir="../new/dest/dir1">
  <fileset dir="src/dir1"/>   
</copy>

or

<copy todir="../new/dest">
  <fileset dir="src" includes="dir1/**"/>
</copy>

See also here and here.


From http://ant.apache.org/manual/Tasks/copy.html:

<copy todir="../new/dir">
  <fileset dir="src_dir"/>
</copy>


This will do it:

<copy todir="directory/to/copy/to">
    <fileset dir="directory/to/copy/from"/>
</copy>

The ant manual is your friend: Ant Manual, in this case: Copy Task

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜