PHP dir cycle

2010-02-08

Cycle through a dir and get all the filenames...

Code: (PHP)
$strDir = 'source'; // no trailing slash
$hndlDir = opendir($strDir);
while (($strFile = readdir($hndlDir)) !== false) {
if ($strFile == '.' && $strFile == '..') {
continue;
} elseif (is_dir($strDir.'/'.$strFile)) {
// dir parsing code
} else {
// file parsing code
}
}

Note that this isn't quite safe regarding symbolic links and stuff like that. But it will suffice in most environments.

Hope it helps ya!