file-helper : get_filenames() returns wrong type of information #746

jaolstad opened this Issue Dec 7, 2011 · 5 comments


None yet
3 participants

jaolstad commented Dec 7, 2011

When executing get_filenames($path), based on the information in the documentation, one would expect to have filenames of the files residing in that directory,$path, only.

Unfortunately this is not the case.

When executing get_filenames($path) against a directory with a subdirectory that contains a single file, the following information is returned:

Array (
[0] => file1.png,
[1] => file.2png

Where the filestructure in $path is as follows:

As I see it, the second file should have been returned as prints/file2.png in order to show that it resides under a sub-directory. Or even better, without specifying recursion; the file, file2.png should not have been returned at all!


ericbarnes commented Dec 7, 2011

That is actually how that function is designed. I think you would be better off using: get_dir_file_info

jaolstad commented Dec 8, 2011

I see, but what use do I have of getting only the name of the files within subfolders?! It would have made sense if the function returned the filenames of the files in the specified folder, but when this function operates recursively, which it appearently does by default, the path to the subfolder should be returned as well.
...or better, there should be a flag where the user/developer could tell the function not to operate recursively.


ericbarnes commented Dec 8, 2011

In that case you probably want: directory_map()

When you look at both it makes sense to me that get_filenames only returns the file names where directory_map shows all files and path.

jaolstad commented Dec 8, 2011

No, that is not what I want at all. I want the get_files($path) method to return only the names of the files which resides within the specified path, NOT underlying paths/subdirs.

E.g. if I have the following folder structure:

  • test
    • test1.txt
    • test2.txt
    • subfolder1
      • subfile1.txt
      • subfile2.txt

If a make a call to get_files('test') using the current version of the method, the following is returned:
[0] = 'test1.txt'
[1] = 'test2.txt'
[2] = 'subfile1.txt'
[3] = 'subfile2.txt'

In my opinion this is WRONG. If I had specified that the get_files($path) method should operate recursively, then this behavior would have been close to ok, but NO.

Calling get_files('test') should return, in my opinion, the following:
[0] = 'test1.txt'
[1] = 'test2.txt'

...since I don't have specified any form of recursion.

If the get_files($path) method is supposed to operate recursively by default, which it clearly does by today, there should be some kind of information returned that will tell the user/callee (me), that some of the files returned are fetched via a subfolder.

[0] = 'test1.txt'
[1] = 'test2.txt'
[2] = 'subfolder1/subfile1.txt'
[3] = 'subfolder1/subfile2.txt'


narfbg commented Jul 18, 2013

Filepaths are included if you pass TRUE as the second parameter for get_filenames().

@narfbg narfbg closed this Jul 18, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment