Skip to content

Instantly share code, notes, and snippets.



Created Jan 5, 2011
What would you like to do?
* Add each directory within ./application to the include path so that each file
* is easily accessible.
function include_subdirectories_in_path()
global $paths;
$paths = array('application');
// Prepare the iterators
$dir = new RecursiveDirectoryIterator('application');
$it = new RecursiveIteratorIterator($dir, RecursiveIteratorIterator::SELF_FIRST);
// Collect all of the directories
foreach ($it as $d) {
if ($d->isDir() && preg_match('/\\.svn/', $path = $d->getPathname()) == 0) {
$paths[] = $path;
// Collate into a path that can singly be added to the include path
$paths = implode(PATH_SEPARATOR, array_map('realpath', $paths));
// Add to the include path
set_include_path(get_include_path() .PATH_SEPARATOR. $paths);
// Store the path components in the global variable
$paths = explode(PATH_SEPARATOR, get_include_path());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment