Ant Tasks

Commons VFS includes several Ant tasks that can be used to create, delete, copy and move files of any supported type. The tasks are:

  • <v-copy> . Copies a set of source folders and files to a destination folder.
  • <v-delete> . Deletes a file or folder.
  • <v-mkdir> . Creates a folder.
  • <v-move> . Moves a set of source folders and files to a destination folder.
  • <v-sync> . Synchronises a destination folder with a set of source folder and files.

All file name attributes support relative and absolute local file names, and absolute URI. File names are interpreted relative to the Ant project's base directory.

Using the Tasks

To use the Ant tasks, copy commons-vfs.jar and its dependencies into the $ANT_HOME/lib directory, and use the following in your Ant scipt to define the tasks:

<taskdef resource="org/apache/commons/vfs/tasks/tasks.properties"/>
                    

Alternatively, you can provide an explicit classpath when you define the tasks:

<taskdef resource="org/apache/commons/vfs/tasks/tasks.properties">
    <classpath> ... </classpath>
</taskdef>
                    

V-Copy

Copies a set of files to a destination folder. Does not copy source files where the destination file exists and is newer than the source file. The copy task takes the following attributes:

NameDescriptionRequired
destdirThe destination folder. This folder is created if it does not exist.One only
destfileThe destination file. Can only be used if there is a single source file.
srcdirThe source folder. If used the includes and desdir attributes should be specified.No
includesA comma or space separated list of files. The files are resolved in combination with the specified srcdir attribute.Only if srcdir is specified.
overwriteAlways copy files, ignoring the last-modified time of the destination file.No, default is false.
preservelastmodifiedSet the last-modified time of destination files to the same value as the source files. May not be supported by the destination file system.No, default is true.
srcdirisbaseSet whether the source directory should be used as base directory. If set to true, the subdirectories of the specified directories will be copied as well.No, default is false.
srcA source file or folder to copy. Copies all descendents of a folder.No

Nested Elements

<src>

Defines a source file or folder to copy. It takes the following attributes:

NameDescriptionRequired
fileThe source file.Yes

V-Move

Moves a set of files to a destination folder. Has the same attributes and elements as the copy task and following attributes:

NameDescriptionRequired
tryRenameThe destination folder. This folder is created if it does not exist.No, default is false

V-Sync

Synchronises a destination folder with a set of source files. Has the same attributes and elements as the copy task.

V-Delete

Deletes a file or folder. It takes the following attributes:

NameDescriptionRequired
fileThe file or folder to delete. All descendents of the folder are deleted.One only
srcdirThe source folder. If used the includes attribute should be specified.
includesA comma or space separated list of files. The files are resolved in combination with the specified srcdir attribute.Only if srcdir is specified.

V-Mkdir

Creates a folder. It takes the following attributes:

NameDescriptionRequired
dirThe folder create.Yes