note 11503 rejected from function.readdir by sander

From: Date: Sat, 06 Apr 2002 19:15:01 +0000
Subject: note 11503 rejected from function.readdir by sander
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-28750@lists.php.net to get a copy of this message
This is a simple function to list the entire contentes of a givendirectory and all of its subdirectories: function GetDirContents($path,&$fileArray) { $currentDir=openDir("$path"); while($dirList = readDir($currentDir)) { if(($dirList!=".")&&($dirList!="..")) { $i=count(&$fileArray); $fileArray[$i] = $path."/".$dirList; $sPath =$fileArray[$i]; if(is_dir($sPath)) { GetDirContents($sPath,&$fileArray); } } } } //Create a variable containing the path //to the initial directory $path = "some directory path"; //Create an array to hold the files $filesArray = array(); //Pass the array by reference GetDirContents($path,&$fileArray) This is very useful when you need to list out the entire contents of a directory, and you need that list for future use. Great if you need to open and manipulate all files in a give directory and its subdirectories without already knowing how many files and subdirectories there are.

« previous php.notes (#28750) next »