fuel / core

Fuel PHP Framework - The core of the Fuel v1 framework
http://fuelphp.com
813 stars 345 forks source link

File::read_dir $filter returns 0 results if the first dir has no valid files #1029

Closed davidfsmith closed 12 years ago

davidfsmith commented 12 years ago

With the structure as below:

array(1) {
  'directory/' =>
  array(5) {
    'directory_1/' =>
    array(3) {
      [0] =>
      string(10) "file_1.zip"
      [1] =>
      string(10) "file_2.zip"
      [2] =>
      string(10) "file_3.zip"
    }
    'directory_2/' =>
    array(3) {
      [0] =>
      string(10) "file_4.zip"
      [1] =>
      string(10) "file_5.zip"
      [2] =>
      string(10) "file_6.zip"
    }
    'directory_3/' =>
    array(3) {
      [0] =>
      string(10) "file_7.zip"
      [1] =>
      string(10) "file_8.zip"
      [2] =>
      string(10) "file_9.zip"
    }
    'directory_4/' =>
    array(3) {
      [0] =>
      string(10) "file_10.zip"
      [1] =>
      string(10) "file_11.zip"
      [2] =>
      string(10) "file_12.zip"
    }
    [0] =>
    string(8) "file.zip"
  }
}

Using:

$files = File::read_dir($directory,0,$filer);

Returns the correct data back, however if 'file.zip' is removed from the top level directory zero files are returned.

WanWizard commented 12 years ago

I don't think this is the case.

It doesn't return anything because the filter is applied to folder names to, so all your directories are filtered out.

You can deal with that by defining the proper filterset, for example

array(
    '^file_[0-9]*.zip$' => 'file',    // only apply this filter on files, not directories
)
davidfsmith commented 12 years ago

Ok so the logic in your response makes sense and I had tried that based on the documentation (http://docs.fuelphp.com/classes/file/usage.html#/method_read_dir), however trying it now again I'm still not seeing it work even with a more simple filterset (as per the doco)

array(
    '\.zip$' => 'file',
);
WanWizard commented 12 years ago

That example works as a charm here. Didn't have a tree of zip files, so I used

    $filter = array(
        '\.php$' => 'file',
    );

    $files = File::read_dir("/var/www/fuelphp",0,$filter);

And it gives me a nice big nested array of all php files in all fuelphp versions I have in that folder. That folder itself only contains other folders, not a single file.

davidfsmith commented 12 years ago

Ok, so this is PEBKAC, resolved with a pull of 1.2/master which I was on (or thought I was) anyway.

Apologies.

sigh