Skipping files in a RecursiveDirectoryIterator loop

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



	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





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux