Advertisement
Sprenger120

Rekrusives Ordnereinlesen

Jun 11th, 2011
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.05 KB | None | 0 0
  1. <?php
  2. $sOutput = GetFilesInDirRec("./"); //Das Aktuelle Verzeichnis durchsuchen
  3. $aFiles = explode("|",$sOutput); // Die Dateien werden als String ausgegeben und mit $sTrennzeichen seperiert... explode wandelt die ganze geschichte in eine array um
  4. var_dump($aFiles); //ausgeben (fΓΌr FF user ist es besser wenn man sich statt der html interpreterausgabe, den quelltext anguckt.. da ist es formatiert)
  5.  
  6. function GetFilesInDirRec($sPath,$Rec=0) {
  7.     //by Sprenger120
  8.     $sTrennzeichen = "|";
  9.     static $sOutput,$sMainPath;
  10.  
  11.     if ($Rec == 0) {
  12.         $sMainPath = $sPath;
  13.         $sOutput = "";
  14.     }
  15.  
  16.     $hDir = opendir($sPath);
  17.  
  18.     while (false !== ($file = readdir($hDir))) {
  19.         if ($file == ".." || $file == ".") { continue; }
  20.         if ($sPath == $sMainPath) {
  21.             $sOutput .= $sTrennzeichen.$sPath.$file;
  22.             if (is_dir($sPath.$file)) { $sOutput = GetFilesInDirRec($sPath.$file,1); }
  23.         } else {
  24.             $sOutput .= $sTrennzeichen.$sPath."/".$file;
  25.             if (is_dir($sPath."/".$file)) { $sOutput = GetFilesInDirRec($sPath."/".$file,1); }
  26.         }
  27.     }
  28.     closedir($hDir);
  29.     return $sOutput;
  30. }
  31.  
  32. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement