directory

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

Deleting Directories With Phing

13th January 2009

Although using Phing is mainly about copying files, you might also need to delete directories and files using the delete element. Remember that the default behavior of copy command copies files only if the source files are different from the destination files. A prudent approach might be to delete the build directory and then recreate it, ready for Phing to copy files into.

Turn Off PHP Parsing In A Directory

23rd December 2008

Sometimes it is necessary to turn off PHP parsing for a directory. You might want to give away some source code and therefore don't want to parse that code when the user tries to download it. You could just rename the file to have the extension .phps, which is a PHP source file, but this is an alternate method.

To turn off PHP parsing in a directory just create a .htaccess file with the following content.

php_flag engine off

You can expand on this by adding the following:

Moving Files In PHP

11th November 2008

I have been asked a couple of times recently if PHP has a function that will move a file, so I thought I would put the solution here.

PHP has a function called rename() which can be used to rename a file, but because of the way it works it can be used to move files. Let's say that you wanted to rename a file called test.txt to test_back.txt, this can be accomplished by doing the following.

Directory Iteration With DirectoryIterator() In PHP 5

26th September 2008

The normal way of looping through a directory is to get a handle on the directory, then go through each item, making sure that the file is readable and is not "." or ".." before doing something with the file. Because this is done a lot the DirectoryIterator() object was created in PHP5 to simplify this process.

The constructor of the DirectoryIterator() object takes a single parameter, this is the path of the directory that is to be iterated over.

Loop Through All Files In A Directory With DOS Batch

16th September 2008
DOS Batch is the Windows equivalent of shell scripting and can be used to perform all sorts of different actions. Anything that you type into a DOS prompt on a Windows machine can be used in a bat file to quickly do something that you would otherwise have to repeat many times over. To create a bat file just make a file and give it the extension "bat". If you run a DOS prompt and navigate to the directory that the bat file exists in you can type the name of the file to get it to do certain actions.

RegExLib.com: The Regular Expression Library

22nd March 2008

Writing regular expressions can sometimes be a real pain, especially if you are not used to them. Rather than trying for yourself to make a regular expression you might want to think about looking for regular expressions that other people have made. Rather than reinventing the wheel to prove you can do something,using free third party regular expressions can save you a lot of time.

Procedure For Changing The Directory Of A Wordpress Blog

1st February 2008

For many sites the blog is only part of the site, not the main reason for the site existing. In these cases the blog is kept in the directory /blog or similar. Occasionally (for what ever reason) it might be necessary to change the directory. To that end here is a small walk through of the steps you need to take in order to do this.