Einzelnen Beitrag anzeigen

Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#15

Re: [PHP] Elemente aus Array löschen

  Alt 24. Aug 2009, 12:46
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_SEPERATOR . $file)) {
                $allData[] = $dir . DIRECTORY_SEPERATOR . $file;
                $allData = ScanDirectories(
                    $dir . DIRECTORY_SEPERATOR . $file,
                    $forbiddenDirs,
                    $allData
                );
            }
        }
        return $allData;
    } else {
        throw new Exception('Failed to open directory: ' . $dir);
    }
}

$allDirs = (ScanDirectories("."));

print_r($allDirs);
Liefert als Ausgabe:
Zitat:
Array ( )
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat