protected function emptyDirectory($directory, $deleteDirectory = false)
	{
		if (!is_dir($directory) || !($directoryHandle = opendir($directory))) {
			return;
		}
		
		while (false !== ($object = readdir($directoryHandle))) 
		{
			if ($object == '.' || $object == '..') {
				continue;
			}

			if (!is_dir($directory.'/'.$object)) {
				unlink($directory.'/'.$object);
			}
			else {
				$this->emptyDirectory($directory.'/'.$object, true);	// The object is a folder, recurse through it.
			}
		}
		
		if ($deleteDirectory)
		{
			closedir($directoryHandle);
			rmdir($directory);
		}
	}
protected function emptyDirectory($directory, $deleteDirectory = false)
	{
		if (!is_dir($directory) || !($directoryHandle = opendir($directory))) {
			return;
		}
		
		while (false !== ($object = readdir($directoryHandle))) 
		{
			if ($object == '.' || $object == '..') {
				continue;
			}

			if (!is_dir($directory.'/'.$object)) {
				unlink($directory.'/'.$object);
			}
			else {
				$this->emptyDirectory($directory.'/'.$object, true);	// The object is a folder, recurse through it.
			}
		}
		
		if ($deleteDirectory)
		{
			closedir($directoryHandle);
			rmdir($directory);
		}
	}
protected function emptyDirectory ( $ directory , $ deleteDirectory = false ) { if ( ! is_dir ( $ directory ) || ! ( $ directoryHandle = opendir ( $ directory ) ) ) { return ; } while ( false !== ( $ object = readdir ( $ directoryHandle ) ) ) { if ( $ object == '.' || $ object == '..' ) { continue ; } if ( ! is_dir ( $ directory . '/' . $ object ) ) { unlink ( $ directory . '/' . $ object ) ; } else { $ this -> emptyDirectory ( $ directory . '/' . $ object , true ) ; // The object is a folder, recurse through it. } } if ( $ deleteDirectory ) { closedir ( $ directoryHandle ) ; rmdir ( $ directory ) ; } }
Recursively delete the files in a directory.

@desc Recursively loops through each file in the directory and deletes it.
@param string $directory
@param boolean $deleteDirectory
@return void
Recursively delete the files in a directory .