Anyone have faster smarter?
<?php
############################################################
############################################################
## Functions: Directory
## Functions designed to work with directories
##
## November 17, 2004
## Geoffrey DeFilippi
##
## Listing:
##
## is_valid_directory( $path, $error (returned will be erased at entry point) ){
## Checks a path to make sure it is valid returns true or false
## and an error message if false
##
## load_directory_dfs( $path (string), $filter (regex expression) )
## Load a directory of files with include_once directive if their
## name match the regex expressions passed in as a string
## or load everything (Depth First)
##
## load_directory_bfs( $path (string), $filter (regex expression) )
## Load a directory of files with include_once directive if their
## name match the regex expressions passed in as a string
## or load everything (Breadth First)
##
############################################################
############################################################
////////////////////////////////////////////////////////////
// INSTALLATION VARIABLE
define( 'INSTALLED_DIRECTORY_FUNCTIONS', 1 );
////////////////////////////////////////////////////////////
// Start Code
function is_valid_directory( $path = "./", &$error) {
$error = "";
if( ! file_exists( $path ) ) {
$error = "Error: Attempting to load from no existant directory. A valid directory is required";
return false;
} elseif ( ! is_dir( $path ) ) {
$error = "Error: Attempting to load file. A directory is required";
return false;
} elseif ( ! is_readable( $path ) ) {
$error = "Error: Directory is not readable. A readable directory is required";
return false;
}
return true;
}
function load_directory_dfs( $path = "./", $filter = '/^.*$/' ) {
$error = "";
if( ! ( is_valid_directory( $path, $error ) ) ) {
die( $error );
}
if( ! $directory = @opendir( $path ) ) {
die( "Unable to open dir: error message here" );
}
while( $file = @readdir( $directory ) ) {
if( ( preg_match( $filter, $file ) ) && ( ! is_dir( $path.$file.'/' ) ) ) {
include_once( $path . $file );
}
elseif ( ( is_dir( $path.$file.'/' ) ) && ( ! preg_match( '/^\.|\.\.$/', $file ) ) ) {
load_directory_dfs( $path.$file.'/', $filter );
}
}
@closedir( $directory );
}
function load_directory_bfs( $path = "./", $filter = '/^.*$/' ) {
$error = "";
if( ! ( is_valid_directory( $path, $error ) ) ) {
die( $error );
}
if( ! $directory = @opendir( $path ) ) {
die( "Unable to open dir: error message here" );
}
$queue = array();
while( $file = @readdir( $directory ) ) {
if( ( preg_match( $filter, $file ) ) && ( ! is_dir( $path.$file.'/' ) ) ) {
include_once( $path . $file );
}
elseif ( ( is_dir( $path.$file.'/' ) ) && ( ! preg_match( '/^\.|\.\.$/', $file ) ) ) {
$queue[] = $path.$file.'/';
}
}
@closedir( $directory );
while( count( $queue ) > 0 ) {
load_directory_bfs( array_shift( $queue ), $filter );
}
}
?>