How Do I Create Directory with Ant

1. Create directory with Ant

To creates a directory, you can simply use ant task Mkdir to create the full tree of directories, when have non-existent parent directories they will be created directly, does nothing if the directory already exist.

<mkdir dir="c:/asjava"/>

Creates a directory asjava in disk C.

<mkdir dir="C:/asjava/lib"/>

Creates a directory asjava and sub directory lib both.

The Attribute ‘dir’ is required and specifics the directory to create.

2. Create directory with ant if does not exist.

<!-- Target #1. Set property value depends on check result -->
<target name="check-dir">
  <available property="no.asjava.dir" file="c:/asjava" type="dir"/>
</target>

<!-- target #2. Create dir 'asjava' if doesn't exist -->
<target name="create-asjava-dir" depends="check-dir" unless="no.asjava.dir">
  <mkdir dir="no.asjava.dir"/>
</target>

It will create folder ‘asjava’ in disk C if it does not exist yet, it used Ant task 'available' to check whether the folder is presenting in disk C.

3. Ant Create directory fail on error.

<mkdir dir="C:/asjava/lib" failonerror="false"/>

For some reasons (e.g. insufficient user privilege) you may not able to create this folder successfully, just make failonerror=false to avoid this error to stop the whole Ant process.

Оцените статью
ASJAVA.COM
Добавить комментарий

Your email address will not be published. Required fields are marked *

*

code