Einzelnen Beitrag anzeigen

Benutzerbild von Valle
Valle

Registriert seit: 26. Dez 2005
Ort: Karlsruhe
1.223 Beiträge
 
#14

Re: [PHP] Elemente aus Array löschen

  Alt 24. Aug 2009, 12:42
Code:
$forbiddenDirs = array("Privat", "Source", "cgi-bin", "data", "luckie-online");

function ScanDirectories($dir, array $forbiddenDirs=array(), array $allData=array())
{
    if ($handle = opendir($dir)) {
        while (false !== ($file = readdir($handle))) {
            if ($file == "." || $file == ".." || in_array($file, $forbiddenDirs)) {
                continue;
            }
            if (is_dir($dir . DIRECTORY_SEPARATOR . $file)) {
                $allData[] = $dir . DIRECTORY_SEPARATOR . $file;
                $allData = ScanDirectories(
                    $dir . DIRECTORY_SEPARATOR . $file,
                    $forbiddenDirs,
                    $allData
                );
            }
        }
        return $allData;
    } else {
        throw new Exception('Failed to open directory: ' . $dir);
    }
}
Ungetestet. Jetzt getestet und verbessert.

Mit freundlichen Grüßen,

Valle
Valentin Voigt
BOFH excuse #423: „It's not RFC-822 compliant.“
Mein total langweiliger Blog
  Mit Zitat antworten Zitat