note 92565 added to function.glob

From: Date: Wed, 29 Jul 2009 15:47:55 +0000
Subject: note 92565 added to function.glob
Groups: php.notes 
Request: Send a blank email to php-notes+get-158884@lists.php.net to get a copy of this message
For those who need to recursively search a directory tree and cannot or wish not to call a function within itself here is another suggestion. I tried the previously suggested listdirs_safe() and it didn't seem to find all subfolders in a directory tree. There are two variations on the same theme. Single Array. <?php $dir ='/dir'; while($dirs = glob($dir . '/*', GLOB_ONLYDIR)) { $dir .= '/*'; if(!$d) { $d=$dirs; } else { $d=array_merge($d,$dirs); } } ?> Multiple arrays. <?php $n=0; $dir ='/dir'; while($dirs = glob($dir . '/*', GLOB_ONLYDIR)) { $dir .= '/*'; if(!$d) { $d=$dirs; } else { $d[$n]=$dirs; } $n++; } ?> This will result in the glob looping via "dir/*/*/*/*.." until it is no longer finding a directory structure. ---- Server IP: 64.71.164.2 Probable Submitter: 99.190.124.20 ---- Manual Page -- http://www.php.net/manual/en/function.glob.php Edit -- https://master.php.net/note/edit/92565 Del: integrated -- https://master.php.net/note/delete/92565/integrated Del: useless -- https://master.php.net/note/delete/92565/useless Del: bad code -- https://master.php.net/note/delete/92565/bad+code Del: spam -- https://master.php.net/note/delete/92565/spam Del: non-english -- https://master.php.net/note/delete/92565/non-english Del: in docs -- https://master.php.net/note/delete/92565/in+docs Del: other reasons-- https://master.php.net/note/delete/92565 Reject -- https://master.php.net/note/reject/92565 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#158884) next »