Zend - The PHP Company




Files and Directories

Add Code


recursive directory listing  

Type: code fragment
Added by: MoreDread
Entered: 06/03/2003
Last modified: 04/12/2002
Rating: - (fewer than 3 votes)
Views: 5856
This mini-script lists your directory structure from a starting point. Nothing special - but small and far from complex and not used for a certain purpose. You could modify and use it for whatever you need.


<?php
// starting directory
$basedir ".";

// function
function listdir($basedir){
    if (
$handle = @opendir($basedir)) {
        while (
false !== ($dir readdir($handle))){
            if (
$dir != '.' || $dir != '..'){
                if (
is_dir($basedir."/".$dir)){
                    echo 
$basedir."/".$dir."<br>";
                    
listdir($basedir."/".$dir);
                }
            }
        }
        
closedir($handle);
    }
}
// function call
listdir($basedir);
?>



Usage Example




Rate This Script





Search



This Category All Categories