You can use the method isDot()
to check if the item is a browser between directories.
<?php
$path = 'pasta_desejada';
$dir = new DirectoryIterator($path);
foreach ($dir as $item) {
if (! $item->isDot()) {
// Faz algo
}
}
But since you’re giving include in various files, perhaps what you are looking for is the RecursiveDirectoryIterator
.
With it you will be able to enter the subdirectories and give the include files (of course, checking before if they are files):
<?php
$path = 'pasta_desejada';
$dir = new RecursiveDirectoryIterator ($path);
$iterator = new RecursiveIteratorIterator($dir);
foreach ($iterator as $item) {
// Verifica se é um arquivo
if ($item->isFile()) {
// Faz algo
}
}
Since they are classes, maybe you want to filter by PHP extension. For this you can combine with more others Iterators
, like the RegexIterator
<?php
$path = 'pasta_desejada';
$dir = new RecursiveDirectoryIterator ($path);
$iterator = new RecursiveIteratorIterator($dir);
$filterIterator= new RegexIterator(
$iterator ,
'/^.+\.php$/i',
RecursiveRegexIterator::GET_MATCH
);
foreach ($iterator as $item) {
// Verifica se é um arquivo
if ($item->isFile()) {
// Faz algo
}
}
There are several ways to do this. Just please do not try to reinvent the wheel. If you are trying to make a autoloader, instead try to use the Composer ;)
Augusto, avoid using snippet for nonexecutable code like html + javascript and/or css are..
– user28595
But when pasting the problem code, only the first line enters...
– Augusto Furlan