Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a recursiveDirectoryIterator like this:

$theme_iterator = new RecursiveIteratorIterator(
    new RecursiveDirectoryIterator($theme_folder_path)
);
foreach ($theme_iterator as $file_object) {
   // Stuff
}

The problem is that it iterates into the .svn hidden folders. How can I prevent this?

Edit:

I can't just add something like this in the foreach because the files from the hidden folder are allready in the array at that point and they are not all hidden.

if (strpos($file_object, ".") ===0) {
    continue;
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
654 views
Welcome To Ask or Share your Answers For Others

1 Answer

<?php
class RecursiveDotFilterIterator extends  RecursiveFilterIterator
{
    public function accept()
    {
        return '.' !== substr($this->current()->getFilename(), 0, 1);
    }
}

$iterator = new RecursiveIteratorIterator(
    new RecursiveDotFilterIterator(
        new RecursiveDirectoryIterator('.')
    )
);
foreach ($iterator as $x) {
    //do stuff
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...