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 =)
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
Edit, Another version without depth count: http://codepad.org/SScJqePV
Please, be more specific with the output you want.
Edit on Comment
This one keeps the path track http://codepad.org/AYDIfLqW
Last Edit
Returning function http://codepad.org/PEG0yuCr