CodeIgniter Forums
get_filenames() works recursively even when explicitly told not to - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: get_filenames() works recursively even when explicitly told not to (/showthread.php?tid=29531)



get_filenames() works recursively even when explicitly told not to - El Forum - 04-12-2010

[eluser]Genki1[/eluser]
The get_filenames() function recursively includes files in the subdirectories, even when the "recursive" parameter is set FALSE:

Code:
$this->load->helper('file');
$aryFilenames = get_filenames('/home/content/html/assets/', TRUE, FALSE);

The following result clearly includes files from the subdirectory "testimonials" which was not specified:

Array
(
[0] => /home/content/html/assets/testimonials/cccs_1.jpg
[1] => /home/content/html/assets/testimonials/chepakho_1.jpg
[2] => /home/content/html/assets/elliott.jpg
[3] => /home/content/html/assets/jgashi.pdf
)

The desired result is to get the files only from the specified directory (unless the recursive flag is set TRUE):

Array
(
[0] => /home/content/html/assets/elliott.jpg
[1] => /home/content/html/assets/jgashi.pdf
)

By the way, the recursive parameter is not mentioned in the User Guide.

I searched the Forums and the Bug Tracker and do not find any mention of this.


get_filenames() works recursively even when explicitly told not to - El Forum - 04-21-2010

[eluser]Octi[/eluser]
Also had problems with this.

Temporary solution:

Go to system/helpers/file_helper.php, line 189 and replace:

Code:
get_filenames($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE);

with

Code:
if($_recursion)
{
   get_filenames($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE);
}

Not sure how this will affect other libraries...


get_filenames() works recursively even when explicitly told not to - El Forum - 04-21-2010

[eluser]Octi[/eluser]
Same thing for get_dir_file_info()


get_filenames() works recursively even when explicitly told not to - El Forum - 04-21-2010

[eluser]WanWizard[/eluser]
Quote:By the way, the recursive parameter is not mentioned in the User Guide.
This is because it is an internal parameter (for both methods), to determine the internal recursion state.
It is not an 'end-user' parameter, you're giving it a meaning that isn't there...

get_dir_file_info() has a $top_level_only parameter that is meant for your purpose, get_filenames() doesn't have such a parameter.


get_filenames() works recursively even when explicitly told not to - El Forum - 04-21-2010

[eluser]Octi[/eluser]
Wondered why it didn't appear in the user guide...

And I guess I should use directory_map($dir, TRUE) to get the contents of a directory, rather than get_filenames().


get_filenames() works recursively even when explicitly told not to - El Forum - 04-21-2010

[eluser]Genki1[/eluser]
It would be helpful if the User Guide sections for "directory_map()" and "get_filenames()" would each mention the existence of the other function. directory_map() actually provides the functionality that I wanted and expected from get_filenames().


get_filenames() works recursively even when explicitly told not to - El Forum - 03-25-2011

[eluser]Nicolas Santos[/eluser]
Hello all,

same bug in 2.0

File_helper line 191
replace
Code:
if (@is_dir($source_dir.$file) && strncmp($file, '.', 1) !== 0)
by
Code:
if (@is_dir($source_dir.$file) && strncmp($file, '.', 1) !== 0 && $_recursion === TRUE )