danscreations Posted December 3, 2008 Share Posted December 3, 2008 Really not sure how to do this and can't seem to find the correct resources to find out. So if there is a simple answer that be great if not a point in the correct direction would be much appreciated. Basicly need to find folder XYZ in several directories which have subdirectores. If the folder XYZ is contained in the directory or sub directories I'm going to use that path. Link to comment https://forums.phpfreaks.com/topic/135356-looking-through-directories-for-cetain-subdirectories/ Share on other sites More sharing options...
premiso Posted December 3, 2008 Share Posted December 3, 2008 scandir opendir Without any attempt at code you probably will not get much help. The following was taken from a comment on the scandir page, I am sure you can tweak it to your needs. <?php /** * returns the folder content names * * @param string $rootDir path to the root folder * @param array $allowext allowed extensions * @param array $notallownames not allowed names * @param array $allData array by reference which collects the root content */ static function ScanDirectories($rootDir, $allowext, $notallownames, &$allData) { $dirContent = scandir($rootDir); static $i=0; foreach($dirContent as $key => $content) { if ($content == '.' || $content == '..') continue; $path = $rootDir . SEPARATOR . $content; $ext = substr($content, strrpos($content, '.') + 1); if(in_array($ext, $allowext) && is_file($path) && is_readable($path) && !in_array($content, $notallownames)) { $allData[$i][name] = $content; $allData[$i][path] = $rootDir; $allData[$i][sub] = ''; } else if(is_dir($path) && is_readable($path) && !in_array($content, $notallownames)) { $allData[$i][name] = $content; $allData[$i][path] = $rootDir; $allData[$i][sub] = array(); self::scanDirectories($path, $allowext, $notallownames, &$allData[$i][sub]); } $i++; } } ?> Link to comment https://forums.phpfreaks.com/topic/135356-looking-through-directories-for-cetain-subdirectories/#findComment-705006 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.