php - recursive directory iterator results: filter out specific characters from resultant paths -
i'm trying return unique instances paths specified directory, recursively.
i'm using recursivedirectoryiterator
. omit instances of paths contain '.' in them, i'm having trouble.
here's i've got going test:
<?php function test($dir){ $dirarray = []; // array store dirs $path = realpath($dir); $dirs = new recursivedirectoryiterator($path, filesystemiterator::skip_dots); $objects = new recursiveiteratoriterator($dirs, recursiveiteratoriterator::self_first); // loop through objects , store names in dirarray[] foreach($objects $name => $object){ if($object->isdir() && strpos($object->getbasename(), '.') !== true) { $dirarray[] = $name; echo "test: " . $object->getbasename() . "\n"; } } print_r($dirarray); } test('/some/dir'); ?>
this code nearly need. returns unique dirs, includes '.' in path name.
just add checker inside, , try use ->getpathname()
instead:
if($object->isdir() && strpos($object->getpathname(), '.') === false) { // stuff }
this means, if directory , if pathname not contain .
Comments
Post a Comment