note 40892 added to function.readdir

From: Date: Thu, 18 Mar 2004 11:13:33 +0000
Subject: note 40892 added to function.readdir
Groups: php.notes 
Request: Send a blank email to php-notes+get-67007@lists.php.net to get a copy of this message
If you want to walk through a directory and want to use a callback function for every dir or file you get you can use this its like the perl File::Find method "find" <?php function find($callback, $dir=Array()) { foreach($dir as $sPath) { if ($handle = opendir($sPath)) { $append = false; while (false !== ($file = readdir($handle))) { if($file !== "." or $file !== "..") { if(is_dir($sPath."/".$file)) { eval("$callback(\"$sPath\", \"$file\");"); find($callback, Array($sPath."/".$file)); } else { eval("$callback(\"$sPath\", \"$file\");"); } } } closedir($handle); } } } function walk($dir, $file) { print ">>> $dir/$file\n"; } find("walk", Array("/etc")); ?> hope it helps jg ---- Manual Page -- http://www.php.net/manual/en/function.readdir.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+40892 Delete -- http://master.php.net/manage/user-notes.php?action=delete+40892&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+40892&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#67007) next »