note 13443 added to class.dir.php

From: Date: Sat, 16 Jun 2001 20:32:31 +0000
Subject: note 13443 added to class.dir.php
Groups: php.notes 
Request: Send a blank email to php-notes+get-14378@lists.php.net to get a copy of this message
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); ?> http://www.php.net/manual/en/class.dir.php

« previous php.notes (#14378) next »