note 60563 added to class.dir

From: Date: Wed, 11 Jan 2006 06:15:20 +0000
Subject: note 60563 added to class.dir
Groups: php.notes 
Request: Send a blank email to php-notes+get-101531@lists.php.net to get a copy of this message
Saw the leaf dirs bit... quick mod: function preg_ls ($path=".", $rec=false, $pat="/.*/") { $pat=preg_replace ("|(/.*/[^S]*)|s", "\\1S", $pat); while (substr ($path,-1,1) =="/") $path=substr ($path,0,-1); if (!is_dir ($path) ) $path=dirname ($path); if ($rec!==true) $rec=false; $d=dir ($path); $ret=Array (); while (false!== ($e=$d->read () ) ) { if ( ($e==".") || ($e=="..") ) continue; if ($rec && is_dir ($path."/".$e) ) { $ret=array_merge ($ret,preg_ls($path."/".$e,$rec,$pat)); continue; } if (!preg_match ($pat,$e) ) continue; $ret[]=$path."/".$e; } return (empty ($ret) && preg_match ($pat,basename($path))) ? Array ($path."/") : $ret; } example: foreach (preg_ls ("/usr/share/fluxbox", true, "/[LT]e[sa]/i") as $file) echo $file."\n"; output: /usr/share/fluxbox/styles/Leaf/ /usr/share/fluxbox/styles/Clean /usr/share/fluxbox/styles/Testing/ ---- Manual Page -- http://www.php.net/manual/en/class.dir.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+60563 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60563&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60563&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60563&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60563&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60563&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60563&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60563&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+60563&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#101531) next »