Jump to content

Recommended Posts

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.

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++;
            }
        }
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.