Jump to content

Directory listing and array


synne

Recommended Posts

Sorry for such a simple question, or at least even I think it is.

What id like to do is create a function for creating a list of directories/folders in a given base directory and turn the results into an array. It does not have to be recursive. No files.

And prefer in alphabetical order

 

BaseUrl = '/';

BaseDir = '/path/to/dir';

 

For each directory create array as such:

 

$config['ResourceType'][] = Array(
                'name' => '$directory_name',
                'url' => $baseUrl . '$directory_name',
                'directory' => $baseDir . '$directory_name',
                'maxSize' => 0,
                'allowedExtensions' => 'htm,html,php,cgi',
                'deniedExtensions' => 'asp');

 

Thanks, and sorry again, Im reading on arrays and how to create the list, figuring out how to put them together is driving me nuts

Link to comment
Share on other sites

You could use the glob() function (docs) to get a list of directories.  The idea being to build up your array in a loop like:

 

 

$directories = glob($baseDir . '/*', GLOB_ONLYDIR);
foreach ($directories as $directory_path) {
    $directory_name = basename($directory_path);
    $config['ResourceType'][] = array(
        'name' => $directory_name,
        'url'  => $baseUrl . $directory_name,
        // and the rest of your array values
    );
}

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.