• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
get_filenames() works recursively even when explicitly told not to

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

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

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

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

#5
[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().

#6
[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().

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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.