Welcome Guest, Not a member yet? Register   Sign In
Reading/Parsing Directories and Files
#2

[eluser]Elliot Haughin[/eluser]
Try something like this for size:

Code:
function read_files($dir)
{
$handle = opendir($dir); // your directory here
$files = array();
if ($handle)
{
    while ( false !== ($file = readdir($handle)) )
    {
        // make sure we don't map silly dirs like .svn, or . or ..
        
        if (substr($file, 0, 1) != ".")
        {
            $files[$file] = array();
                        if (is_dir($dir.'/'.$file) $files[$file] = read_files($dir.'/'.$file);
        }
    }
}
return $files;
}

This should dynamically traverse an entire structure and return an array accordingly... like:

Code:
array(
     'directory1' => array('directory2' => array('file1', 'file2'), 'file3')
);

Hope this helps.


Messages In This Thread
Reading/Parsing Directories and Files - by El Forum - 02-16-2008, 09:27 PM
Reading/Parsing Directories and Files - by El Forum - 02-17-2008, 06:41 AM
Reading/Parsing Directories and Files - by El Forum - 02-17-2008, 07:36 AM
Reading/Parsing Directories and Files - by El Forum - 02-17-2008, 10:45 AM



Theme © iAndrew 2016 - Forum software by © MyBB