Create A File Or Directory With Phing

Wednesday, January 14, 2009 - 15:56

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

Category: 
philipnorton42's picture

Philip Norton

Phil is the founder and administrator of #! code and is an IT professional working in the North West of the UK.
Google+ | Twitter

Comments

Add new comment