3

I am using the SF2 Finder Component to access a directory and grab the subdirectories inside it.

This is my code:

$finder = new Finder();
$dirs = $finder->directories()->in($this->getParameter('crmpicco.image_upload_path'));

The image_upload_path contains 3 directories: /small, /medium and /large

When I dump out the dirs attribute of what Finder returns I get:

  -dirs: array:1 [▼
    0 => "/var/www/crmpicco/20150805093500/app/files/import_images"
  ]

How can I modify this call to access /small, /medium and /large ?

1
  • dirs is a private property, how are you accessing it? Can you please post the code that dump the results? Commented Feb 29, 2016 at 18:23

1 Answer 1

5

I suggested to use a wildcard but after some tests, it seems that the result is the same with or without a wildcard.

With getIterator() I was able to lists all the children of a directory. On my filesystem there is a /var/www/ containing a html directory.

$finder = new \Symfony\Component\Finder\Finder();
$dirs = $finder->directories()->in('/var/www')->depth('< 1');
foreach($dirs->getIterator() as $iterator) {
    print_r($iterator);
}

This code return this:

Symfony\Component\Finder\SplFileInfo Object
(
    [relativePath:Symfony\Component\Finder\SplFileInfo:private] => 
    [relativePathname:Symfony\Component\Finder\SplFileInfo:private] => html
    [pathName:SplFileInfo:private] => /var/www/html
    [fileName:SplFileInfo:private] => html
)

So I think the problem is due to the fact that you use a private property of Finder instead of calling getIterator():

When I dump out the dirs attribute of what Finder returns I get:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.