to only access the current folder:
$max_depth = 0;(PHP 5 >= 5.1.0, PHP 7, PHP 8)
RecursiveIteratorIterator::setMaxDepth β Π£ΡΡΠ°Π½ΠΎΠ²ΠΊΠ° ΠΌΠ°ΠΊΡΠΈΠΌΠ°Π»ΡΠ½ΠΎΠΉ Π³Π»ΡΠ±ΠΈΠ½Ρ Π²Π»ΠΎΠΆΠ΅Π½Π½ΠΎΡΡΠΈ
ΠΠ°Π΄Π°ΡΡ ΠΌΠ°ΠΊΡΠΈΠΌΠ°Π»ΡΠ½ΡΡ Π³Π»ΡΠ±ΠΈΠ½Ρ Π²Π»ΠΎΠΆΠ΅Π½Π½ΠΎΡΡΠΈ ΡΠ»Π΅ΠΌΠ΅Π½ΡΠΎΠ².
Π€ΡΠ½ΠΊΡΠΈΡ ΠΏΠΎΠΊΠ° Π½Π΅ Π·Π°Π΄ΠΎΠΊΡΠΌΠ΅Π½ΡΠΈΡΠΎΠ²Π°Π»ΠΈ; Π΄Π»Ρ Π·Π½Π°ΠΊΠΎΠΌΡΡΠ²Π° Π΄ΠΎΡΡΡΠΏΠ΅Π½ ΡΠΎΠ»ΡΠΊΠΎ ΡΠΏΠΈΡΠΎΠΊ Π°ΡΠ³ΡΠΌΠ΅Π½ΡΠΎΠ².
maxDepth
ΠΠ°ΠΊΡΠΈΠΌΠ°Π»ΡΠ½ΠΎ Π΄ΠΎΠΏΡΡΡΠΈΠΌΠ°Ρ Π³Π»ΡΠ±ΠΈΠ½Π° Π²Π»ΠΎΠΆΠ΅Π½Π½ΠΎΡΡΠΈ. -1 ΡΠ½ΠΈΠΌΠ°Π΅Ρ
ΠΎΠ³ΡΠ°Π½ΠΈΡΠ΅Π½ΠΈΠ΅ Π½Π° Π³Π»ΡΠ±ΠΈΠ½Ρ ΡΠ΅ΠΊΡΡΡΠΈΠΈ.
Π€ΡΠ½ΠΊΡΠΈΡ Π½Π΅ Π²ΠΎΠ·Π²ΡΠ°ΡΠ°Π΅Ρ Π·Π½Π°ΡΠ΅Π½ΠΈΡ ΠΏΠΎΡΠ»Π΅ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΡ.
ΠΡΠ±ΡΠ°ΡΡΠ²Π°Π΅Ρ ΠΈΡΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅ Exception, Π΅ΡΠ»ΠΈ
Π°ΡΠ³ΡΠΌΠ΅Π½Ρ maxDepth ΠΌΠ΅Π½ΡΡΠ΅ -1.
I didn't understand what to do with this statement:
RecursiveIteratorIterator::setMaxDepth ([ int $max_depth = -1 ] ) : void
So, after finding the answer, this is how you incorporate it (for anyone else who was stuck for a while like me!):
// define the depth of the tree to which you want to search
// where -1 = show all layers below the parent
// and 1 = show the first layer, etc, etc
$max_depth = -1;
// set the path to the directory
$this_directory
// do the search
$recursive = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this_directory));
// now adjust the contents to your desired depth
$recursive->setMaxDepth($max_depth);