note 15589 added to function.readdir

From: Date: Fri, 21 Sep 2001 19:39:48 +0000
Subject: note 15589 added to function.readdir
Groups: php.notes 
Request: Send a blank email to php-notes+get-18150@lists.php.net to get a copy of this message
A concise listing of directories and files contained by a directory. Directory names end with a / to dinstinguish them from file names. Just for ease of further processing (e.g. directory mirroring). Note: when declaring variables, their type is indicated within /**/. I think it's a useful way to document them. function listDir( /*string*/$path, //directory path terminated by / /*string[]*/&$files //array of directory and file names ){ /*int*/$dir = openDir($path); while(/*string*/$item = readDir($dir)){ if(($item == ".") || ($item == "..")) continue; //skip endless looping /*string*/$itempath = "$path$item"; if(is_dir($itempath)){ $itempath .= '/'; //trailing / for a directory listDir($itempath, $files); //recursive call } $files[] = $itempath; } closedir($dir); } //Usage : //$DirPath has been initialized with the directory path you want to list. listDir($DirPath, $files=array()); for($i=0,$m=count($files);$i<$m;$i++) echo "$files[$i]<br>"; http://www.php.net/manual/en/function.readdir.php

« previous php.notes (#18150) next »