note 21597 added to function.readdir

From: Date: Mon, 20 May 2002 19:16:37 +0000
Subject: note 21597 added to function.readdir
Groups: php.notes 
Request: Send a blank email to php-notes+get-30810@lists.php.net to get a copy of this message
Nice recursive code. It generates and displays a sorted list of all directories, sudirectories and files of your HD. <?php function GetFileList($path, &$a) { $d=array(); $f=array(); $nd=0; $nf=0; $hndl=opendir($path); while($file=readdir($hndl)) { if ($file=='.' || $file=='..') continue; if (is_dir($path.'\\'.$file)) $d[$nd++]=$file; else $f[$nf++]=$file; } closedir($hndl); sort($d); sort($f); $n=1; for ($i=0;$i<count($d);$i++) { GetFileList($path.'\\'.$d[$i].'\\', $a[$n]); $a[$n++][0]=$d[$i]; } for ($i=0;$i<count($f);$i++) { $a[$n++]=$f[$i]; } } function ShowFileList(&$a, $N) { for ($i=1;$i<count($a); $i++) if (is_array($a[$i])) { echo "<H".$N.">".$a[$i][0]. "</H".$N.">\n"; ShowFileList($a[$i], $N+1); } else echo "<Normal>".$a[$i]. "</Normal>\n"; } echo ("Thanks to FX."); GetFileList("c:\\",$array); ShowFileList($array, 1); ?> -- http://www.php.net/manual/en/function.readdir.php http://master.php.net/manage/user-notes.php?action=edit+21597 http://master.php.net/manage/user-notes.php?action=delete+21597 http://master.php.net/manage/user-notes.php?action=reject+21597

« previous php.notes (#30810) next »