Create A File Or Directory With Phing

14th January 2009

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).

 

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

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

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.

 

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

Permalink
Thank you mate, very helpful.

Claudio (Wed, 08/21/2013 - 11:09)

Add new comment

The content of this field is kept private and will not be shown publicly.