Create A File Or Directory With Phing

After following the last post on deleting files and directories in Phing you might now be wondering if you can create things as well. The answer is yes.

To create a directory with Phing you need to use the mkdir element. The dir attribute is used to give the name of the directory to be created. The following example will create a directory called myProject_build in the current working directory (ie. where you are running phing from).

<mkdir dir="myProject_build" />

That is about as complicated as the mkdir element gets, although you can also pass a parameter to the dir attribute.

<mkdir dir="${projectDirectory}" />

To create a file with Phing you need to use the touch element. The file attribute is used to give the name of the file being created.

<touch file="README.txt" />

You can optionally include one of two date attributes in the touch element. This are datetime (as a date string) and millis (as an integer timestamp) which set the creation timestamp of the file. If you don't include either of these attributes then the current time stamp (ie. now) will be used instead.

Automated Build With Phing

Comments

Thank you mate, very helpful.
Permalink

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
1 + 6 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.