note 29039 deleted from function.readdir by tularis

From: Date: Sun, 13 May 2007 19:07:11 +0000
Subject: note 29039 deleted from function.readdir by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-126556@lists.php.net to get a copy of this message
Note Submitter: php at silisoftware dot com ---- Yet another recursive directory listing script. This one returns a list of all absolute filenames (files only, no directories) in or below the directory first specified in $DirectoriesToScan. $DirectoriesToScan = array(realpath('.')); $DirectoriesScanned = array(); while (count($DirectoriesToScan) > 0) { foreach ($DirectoriesToScan as $DirectoryKey => $startingdir) { if ($dir = @opendir($startingdir)) { while (($file = readdir($dir)) !== false) { if (($file != '.') && ($file != '..')) { $RealPathName = realpath($startingdir.'/'.$file); if (is_dir($RealPathName)) { if (!in_array($RealPathName, $DirectoriesScanned) && !in_array($RealPathName, $DirectoriesToScan)) { $DirectoriesToScan[] = $RealPathName; } } elseif (is_file($RealPathName)) { $FilesInDir[] = $RealPathName; } } } closedir($dir); } $DirectoriesScanned[] = $startingdir; unset($DirectoriesToScan[$DirectoryKey]); } } $FilesInDir = array_unique($FilesInDir); sort($FilesInDir); foreach ($FilesInDir as $filename) { echo $filename."\n"; }

« previous php.notes (#126556) next »