Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8433159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:18:38+00:00 2026-06-10T06:18:38+00:00

I’m trying to figure out how to use this directory_map function in CodeIgniter. See

  • 0

I’m trying to figure out how to use this directory_map function in CodeIgniter.
See the manual for more details here: http://codeigniter.com/user_guide/helpers/directory_helper.html

Here is what I have working (kind of) and the result bellow:

$this->load->helper('directory');
$map = directory_map('textfiles/');

$index = '';

foreach ($map as $dir => $file) {
  $idx .= "<p> dir: {$dir} </p> <p> file: {$file} </p>";
} #foreach

return $idx;

My testing environment directory and files structure:

one [directory]
  subone [sub-directory]
    testsubone.txt [file-in-sub-directory]
  testone.txt [file-in-directory-one]
three [directory]
  testthree.txt [file-in-directory-three]
two [directory]
  testing [sub-directory]
    testagain.txt [file-in-sub-directory-testing]
  test.txt [file-in-directory-testing]
test.txt [file]

This is the output result I have in my view:

dir: 0
dir: two
file: Array
dir: three
file: Array
dir: 1
file: test.txt
dir: one
file: Array

As you can see in this result that not all directories or files are listed, some are showing up as an array.

There is also something called “get_filenames” function in file helper. Maybe it can be used somehow with directory_map.

Also, I get this following errors:

A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: welcome.php
Line Number: #

Any help will be greatly appreceated. Thank you =)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:18:40+00:00Added an answer on June 10, 2026 at 6:18 am

    You’re issue is that you’re trying to print out a multi dimensionnal array.

    You should try doing this instead :
    With depth count http://codepad.org/y2qE59XS

    $map = directory_map("./textfiles/");
    
    function print_dir($in,$depth)
    {
        foreach ($in as $k => $v)
        {
            if (!is_array($v))
                echo "<p>",str_repeat("&nbsp;&nbsp;&nbsp;",$depth)," ",$v," [file]</p>";
            else
                echo "<p>",str_repeat("&nbsp;&nbsp;&nbsp;",$depth)," <b>",$k,"</b> [directory]</p>",print_dir($v,$depth+1);
        }
    }
    
    print_dir($map,0);
    

    Edit, Another version without depth count: http://codepad.org/SScJqePV

    function print_dir($in)
    {
        foreach ($in as $k => $v)
        {
            if (!is_array($v))
                echo "[file]: ",$v,"\n";
            else
                echo "[directory]: ",$k,"\n",print_dir($v);
        }
    }
    
    print_dir($map);
    

    Please, be more specific with the output you want.

    Edit on Comment
    This one keeps the path track http://codepad.org/AYDIfLqW

    function print_dir($in,$path)
    {
        foreach ($in as $k => $v)
        {
            if (!is_array($v))
                echo "[file]: ",$path,$v,"\n";
            else
                echo "[directory]: ",$path,$k,"\n",print_dir($v,$path.$k.DIRECTORY_SEPARATOR);
        }
    }
    
    print_dir($map,'');
    

    Last Edit
    Returning function http://codepad.org/PEG0yuCr

    function print_dir($in,$path)
    {
        $buff = '';
        foreach ($in as $k => $v)
        {
            if (!is_array($v))
                $buff .= "[file]: ".$path.$v."\n";
            else
                $buff .= "[directory]: ".$path.$k."\n".print_dir($v,$path.$k.DIRECTORY_SEPARATOR);
        }
        return $buff;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.