You can use the isDot()
method to verify that 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 are giving include to multiple files, perhaps what you are looking for is RecursiveDirectoryIterator
.
With it you will be able to enter the subdirectories and give include in the files (of course, checking beforehand 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 these are classes, you might want to filter by the PHP extension . For this you can combine with other Iterators
, such as 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 do an autoloader , instead try Composer ;)