Welcome Guest, Not a member yet? Register   Sign In
get_filenames() works recursively even when explicitly told not to

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

$aryFilenames = get_filenames('/home/content/html/assets/', TRUE, FALSE);

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

[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):

[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.

Also had problems with this.

Temporary solution:

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

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


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

Not sure how this will affect other libraries...

Same thing for get_dir_file_info()

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.

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().

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().

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

same bug in 2.0

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

Theme © iAndrew 2016 - Forum software by © MyBB