Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore any subfolder in the finder component?

Tags:

php

symfony

Assume a file structure:

config
    └── folder
        └── subfolder

I want to iterate over the files using the finder component of only the content folder using the symfony finder component but not any subfolder.

Currently, the only way I found to exclude the subfolder is a hardcoded:

foreach($fileFinder->in($portalConfigPath)->files()->exclude('subfolder') as $file) {...}

How to exclude any new subfolder that may be added in the future? I tried '*' as a wildcard, yet it doesn't work here.

like image 650
k0pernikus Avatar asked Feb 12 '16 16:02

k0pernikus


1 Answers

You can set the depth to 0 to not traverse to subfolders:

foreach ($fileFinder->in($portalConfigPath)->files()->depth('== 0') as $file) {...}
like image 189
Jason Roman Avatar answered Nov 04 '22 18:11

Jason Roman