AW: [PHP] Help with recursive function
| From: | Robert Stoll | Date: | Fri, 06 Feb 2015 09:09:17 +0000 |
| Subject: | AW: [PHP] Help with recursive function | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-324397@lists.php.net to get a copy of this message | ||
Hey Jeffry,
> -----Ursprüngliche Nachricht-----
> Von: Jeffry Killen [mailto:jekillen@prodigy.net]
> Gesendet: Freitag, 6. Februar 2015 07:40
> An: PHP General
> Betreff: [PHP] Help with recursive function
>
> Hello again;
>
> I am writing a recursive file system reading method (just for the challenge, i am re inventing
> a wheel)
>
> and I am only getting to the third level below the initial dir when I know there is five levels
> below.
>
> I don't see why:
>
> private function getDirList($_dir)
> {
> $_out = array();
> $_valid = '';
> $_DR = opendir($_dir);
> while($_x = readdir($_DR))
> {
> switch($_x)
> {
> case '.':
> case '..':
> break;
> default:
> if(is_dir($_x))
> {
> $_valid = self::screen($_dir.'/'.$_x, 'dir');
> if($_valid['error'])
> {
> self::$_readError[count(self::
> $_readError)] = $_valid['error'];
> continue;
> }
> else if($_valid['pass'])
> {
> self::$_dirsToRead[$_dir.'/'.$_x] = true;
> self::getDirList($_dir.'/'.$_x); ///<<<<
> this should accumulate directories, shouldn't
it?
> }
> }
> else if(is_file)
> {
> continue;
> }
> break;
> }
> }
> closedir($_DR);
> }
>
> thank you for time and attention
> JK
>
> --
> PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
> http://www.php.net/unsub.php
I do not see that you are actually doing something with the directories. You never store them in
$_out nor are you
returning $_out. Might this be the error? Probably you omitted some code, if so, then please provide
the whole code (you
could past it to 3v4l.org and provide the link)
One other thing I spotted is the else if branch:
else if(is_file)
should be
else if(is_file($_x))
Cheers,
Robert