note 13443 modified in class.dir by goba

From: Date: Wed, 14 Aug 2002 21:23:28 +0000
Subject: note 13443 modified in class.dir by goba
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-35034@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); ?> --was-- 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 (#35034) next »