I have this PHP Code:
$rootpath = \'../admin/\';
$inner = new RecursiveDirectoryIterator($rootpath);
$fileinfos = new RecursiveIteratorIterator($inner);
for
I suggest using the RecursiveCallbackFilterIterator.
$directory = '../admin/';
$filter = array('.git');
$fileinfos = new RecursiveIteratorIterator(
new RecursiveCallbackFilterIterator(
new RecursiveDirectoryIterator(
$directory,
RecursiveDirectoryIterator::SKIP_DOTS
),
function ($fileInfo, $key, $iterator) use ($filter) {
return $fileInfo->isFile() || !in_array($fileInfo->getBaseName(), $filter);
}
)
);
foreach($fileinfos as $pathname => $fileinfo) {
//...
}
I would do it like this:
$excludes = array(
'files' => array('file1.ext','file2.ext','fileN.ext'),
'dirs' => array('dir1','dir2','dirN')
);
foreach ($directories as $current_dir) {
if (!in_array($current_dir,$excludes['dirs'])) {
// directory method
foreach ($files as $current_file) {
if (!in_array($current_file,$excludes['files'])) {
// files method
}
}
}
}