note 13443 deleted from class.dir by aidan

From: Date: Sun, 05 Sep 2004 07:22:45 +0000
Subject: note 13443 deleted from class.dir by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-76045@lists.php.net to get a copy of this message
Note Submitter: n_goodnight at coloradocollege dot edu ---- This is a recursive algorithm for dumping the contents of any directory into a multidimensional array. Files are indexed numerically and directories are indexed associatively. You can then use whatever algorithm you want to view the array. <?php function recursive_ls($listing, $directory, $count) { $dummy = $count; if ($handle = opendir($directory)) { while ($file = readdir($handle)) { if ($file=='.' || $file=='..') continue; else if ($h = @opendir($directory.$file."/")) { closedir($h); $count = -1; $listing["$file"] = array(); recursive_ls(&$listing["$file"], $directory.$file."/", $count + 1); } else { $listing[$dummy] = $file; $dummy = $dummy + 1;} }} closedir($handle); return ($listing); } //Example call $testlist = recursive_ls(array(), "/home/nolan/tarballs/", 0); ?>

« previous php.notes (#76045) next »