note 42549 added to function.readdir

From: Date: Thu, 20 May 2004 22:30:04 +0000
Subject: note 42549 added to function.readdir
Groups: php.notes 
Request: Send a blank email to php-notes+get-69891@lists.php.net to get a copy of this message
Ok you have seen a bunch of them recursive directory functions, but heres mine that loads them all into an array and emdeded arrays that contain all the file names. /*********************************************/ $main_dir = "downloads"; $A_main = Array($main_dir,); $start =& $A_main; $j = 0; function dir_recurse($dir,&$wia) { $i = 1; if($handle = opendir($dir)) { while(false !== ($file = readdir($handle))) { if($file != "." && $file != ".." ) { if(is_dir($dir."/".$file) == true) { $fullpath = $dir."/".$file; array_push($wia,array($file)); dir_recurse($fullpath,$wia[$i]); $i++; } else { $fullpath = $dir."/".$file; array_push($wia,$fullpath); $i++; } } } closedir($handle); } } dir_recurse($main_dir,$start); /********************************************/ wia stands for "where it's at" in relation to being in a directory. ---- Manual Page -- http://www.php.net/manual/en/function.readdir.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+42549 Delete -- http://master.php.net/manage/user-notes.php?action=delete+42549&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+42549&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#69891) next »