Skipping files in a RecursiveDirectoryIterator loop

From: Date: Sun, 19 Nov 2017 22:20:19 +0000
Subject: Skipping files in a RecursiveDirectoryIterator loop
Groups: php.general 
Request: Send a blank email to php-general+get-326269@lists.php.net to get a copy of this message
I want to iterate over every file in a particular directory, and all it's sub-directories. I'm using the code below and it works fine, but I'd like to know if I've done this properly, or if there's a better way to skip certain files and directories. Thanks, Jenni $rdi = new RecursiveDirectoryIterator($lists); foreach (new RecursiveIteratorIterator($rdi) as $file) { // To skip the . and .. directories if (substr($file->getFilename(), -1) == '.') { continue; } // To skip any files that begin with -- if (substr($file->getFilename(), 0, 2) == '--') { continue; } // To skip any directories that begin with -- if (substr($rdi, 0, 2) == '--') { continue; } // process files... }

« previous php.general (#326269) next »