Web lists-archives.com

[PHP] Skipping files in a RecursiveDirectoryIterator loop




	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...
}
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php