Merhaba, Ziyaretçi. Lütfen giriş yapın veya üye olun.
Aktivasyon mailiniz gelmediyse buraya tıklayın.
09, 2008, 02:45:57 am
42744 Mesaj 8090 Konu Gönderen: 17931 Üye
Son üye: medist
Turk-Php.Com Forum  |  Yardım Forumları  |  PHP Yardım Forumu  |  PHP Class Deposu  |  Dizin Listeleyen Sınıf « önceki sonraki »
Sayfa: [1] Yazdır
Yazan Konu: Dizin Listeleyen Sınıf  (Okunma Sayısı 200 defa)
phparmy
phparmy
PHP Stajyeri
**
Offline Offline

Mesaj Sayısı: 371


Elektronik imzam.


Üyelik Bilgileri
Dizin Listeleyen Sınıf
« : 14, 2008, 04:16:13 am »

Sınıf
Kod:
<?php

//=========================================================
// class "DeepDir" take files from all nested directories
// Using:
//
//  $dirName = '..';
//  $dir = new DeepDir();
//  $dir->setDir( $dirName );
//  $dir->load();
//  foreach( $dir->files as $pathToFile ){
//    echo $pathToFile."\n";
//  }
//

class DeepDir{

  var 
$dir;
  var 
$files;

  function 
DeepDir(){
    
$this->dir '';
    
$this->files = array();
    
$this->dirFILO = new FILO();
  }

  function 
setDir$dir ){
    
$this->dir $dir;
    
$this->files = array();
    
$this->dirFILO->zero();
    
$this->dirFILO->push$this->dir );
  }


  function 
load(){
    while( 
$this->curDir $this->dirFILO->pop() ){
      
$this->loadFromCurDir();
    }
  }

  function 
loadFromCurDir(){
    if ( 
$handle = @opendir$this->curDir ) ){
      while ( 
false !== ( $file readdir$handle ) ) ){
        if ( 
$file == "." || $file == ".." ) continue;
        
$filePath $this->curDir '/' $file;
        
$fileType filetype$filePath );
        if ( 
$fileType == 'dir' ){
          
$this->dirFILO->push$filePath );
          continue;
        }
        
$this->files[] = $filePath;
      }
      
closedir$handle );
    }
    else{
      echo 
'error open dir "'.$this->curDir.'"';
    }
  }

// end class


//================================
// stack: First In Last Out
//
class FILO{

  var 
$elements;
  
  function 
FILO(){
    
$this->zero();
  }

  function 
push$elm ){
    
array_push$this->elements$elm );
  }

  function 
pop(){
    return 
array_pop$this->elements );
  }

  function 
zero(){
    
$this->elements = array();
  }

// end class FILO

?>


Kullanım
Kod:
<?php
  $dirName 
'a';
  
$dir = new DeepDir();
  
$dir->setDir$dirName );
  
$dir->load();
  foreach( 
$dir->files as $n => $pathToFile ){
    echo (
$n+1)." ".$pathToFile."\n";
  }
?>

Logged
Sayfa: [1] Yazdır 
« önceki sonraki »
Gitmek istediğiniz yer:  


Turk-Php.Com Forum | SMF Forum Software © 2005, Simple Machines LLC. All Rights Reserved.