next up previous contents index
Next: Copydir Up: Copy Previous: Parameters specified as nested   Contents   Index

Examples

Copy a single file

  <copy file="myfile.txt" tofile="mycopy.txt"/>
Copy a single file to a directory
  <copy file="myfile.txt" todir="../some/other/dir"/>
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"/>
    <mapper type="glob" from="*" to="*.bak"/>
  </copy>
Copy a set of files to a directory, replacing @TITLE@ with Foo Bar in all files.
  <copy todir="../backup/dir">
    <fileset dir="src_dir"/>
    <filterset>
      <filter token="TITLE" value="Foo Bar"/>
    </filterset>
  </copy>
Unix Note: File permissions are not retained when files are copied; they end up with the default UMASK permissions instead. This is caused by the lack of any means to query or set file permissions in the current Java runtimes. If you need a permission-preserving copy function, use <exec executable="cp" ... > instead.

Windows Note: If you copy a file to a directory where that file already exists, but with different casing, the copied file takes on the case of the original. The workaround is to delete the file in the destination directory before you copy it.



Andrew Marlow 2003-07-08