3

I am building a script to import image sets. Each imageset is contained in a directory but the depth of the deepest directory is unknown. It could be 1, 2, 3, 4 or more.

Now I want to use the Symfony Finder component to get a list of the deepest directories. So I can filter out the images in that directory and group them.

Or maybe a better solution would be to filter out all images using:

$files = Finder::create()
    ->in($path)
    ->files()
    ->date('until 1 hour ago')
    ->name('/\.(' . implode('|', $this->extensions) . ')$/')
    ->exclude('.gitignore');

But now I have an array with all the images but I need to group them bij their deepest directory so that I have a multidimensional array with as key the deepest directory. For example:

[
    '/path1/path2' => ['/path1/path2/img1', '/path1/path2/img2', ...],
    '/path1/path3/path4' => ['/path1/path3/path4/img3', '/path1/path3/path4/img4', ...],
    ...
]

0

Your Answer

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

Browse other questions tagged or ask your own question.