Re: recursive direcotry listing

From: Date: Thu, 05 Feb 2004 06:00:31 +0000
Subject: Re: recursive direcotry listing
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-176868@lists.php.net to get a copy of this message
I don't know if there's a built-in function, but I had written this function, which does what you're trying to do, I think. You can modify it to store the values in an array, if you like. I just have it echoing the files (with their full paths). Here's the function: function readDir ($dirPath) {
    if (is_dir($dirPath)) {
        $fstream = opendir($dirPath);
        while ($fentry = readdir($fstream)) {
            if (is_dir("$dirPath/$fentry") && ($fentry != ".") && ($fentry != "..")) {
                echo "$dirPath/$fentry";
                readDir("$dirPath/$fentry");
            } elseif (is_file("$dirPath/$fentry")) {
                echo "$dirPath/$fentry";
            }
        }
        closedir($fstream);
        return true;
    } else {
        return false;
    }
} Hope this helps! -Ben Binay wrote:
Hi all, is there function which scans a particual directory recurisly and stores the content in array or other way? Listing of files should be in alphabetical way and directories should come on top. Thanks Binay


« previous php.general (#176868) next »