PHP Classes

File: dir.class.php

Recommend this page to a friend!
  Classes of tzztztszrzrrz   DIR   dir.class.php   Download  
File: dir.class.php
Role: ???
Content type: text/plain
Description: class file
Class: DIR
Author: By
Last change:
Date: 22 years ago
Size: 5,689 bytes
 

Contents

Class file image Download
<? //########## WARNING #################################################### //# ### //# This is a V.L.E.T. FUNCTION ( VERY LONG EXECUTION TIME FUNCTION ) ### //# ### //########## WARNING #################################################### /* ######################################################################### # Dir ################################################ Version 0.1 beta # ------------------------------------------------------------------------- Nothing ------------------------------------------------------------------------- ###################################### by privat@hpherzog.de (docebola) # ######################################################################### */ // At first you must define the const "PATH_SEP", because // the slashes can be back or normal. Look for your OS ! define ("PATH_SEP","\\"); // Win32 "\" | Linux,Unix "/" // You can see that a lot of class vars and methods are not in // use yet. The reason is, that this is the first release of the // class "Dir" and i was testing some ways to get the best. // If you want to test this class look at the next lines. // $rootDir = "d:\Programme\Apache\htdocs"; // $dir = new Dir($rootDir); // $dir->initRead($dir); // If you have done this, you get all pathes wich are under the // rootpath. class Dir { //var $name; var $path; //var $id; //var $parent; //var $numChilds; //var $haveChilds; function Dir($path) { //$this->name = basename($path); $this->path = $path; //$this->id = $this->getId($path); //$this->parent = $this->getParent($path); //$this->numChilds = $this->getNumChilds($path); //$this->haveChilds = $this->haveChilds($path); } // not in use "bool haveChilds(string $path){}" function haveChilds($path) { $childs = $this->dirChilds($path); if (!$childs) return false; else return true; } // not in use "int getId(string $path){}" function getId ($path) { $parent = $this->getParent($path); $dir = $this->dirChilds($parent); for ($i=0; $i < count($dir); $i++) { if ($dir[$i]==$path) return $i; } } // not in use "object getChild(int $ini=0){}" function getChild ($ini=0) { $child = $this->getChildById($ini); $dir = new Dir($child); return $dir; } // not in use "string getChildById(int $id){}" function getChildById($id) { $childs = $this->dirChilds($this->DIR_VARS["path"]); if (empty($childs[$id])) return false; return $childs[$id]; } // not in use "string getParent(string $path){}" function getParent ($path) { $all = explode(PATH_SEP,$path); $last = array_pop($all); $parent = implode(PATH_SEP,$all); if (count($all)==0) return false; else return $parent; } // not in use "int getNumChilds(string $path){}" function getNumChilds ($path) { $dir = $this->dirChilds($path); if (empty($dir)) return 0; $num = count($dir); return $num; } //################ //# getAllChilds # //################ function getAllChilds ($path) { if($childs = $this->dirChilds($path)) { for($i=0; $i < count($childs); $i++) { $childs[$i] = new Dir($childs[$i]); } return $childs; } else { return false; } } //############# //# dirChilds # //############# // Die Funktion "mixed dirChilds(string $path){}" gibt alle Kindordner, // des aktuellen Ordners "$this->path" zurück. function dirChilds ($path){ // dirChilds -> $files = $this->readDir($path); // -> liest den Ordner aus if ($dir=$this->getDir($files)) return $dir; // -> filtert alle Ordner, und gibt sie in einem Array zurück else return false; // -> gibt "false" zurück, wenn keine Ordner existieren } //########## //# getDir # //########## // Die Funktion "mixed getDir(array $files){}" filtert alle Ordner. // Wenn keine Ordner existieren wird "false" zurückgegeben. function getDir ($files) { $d=0; // Zähler für die Ordner for ($i=0; $i < count($files); $i++) { if (is_dir($files[$i])) { // Wenn der Pfad ein gültiger Ordner ist -> $dir[$d]=$files[$i]; // -> wird er in "$dir" gespeichert $d++; } } if (empty($dir)) return false; else return $dir; } //########### //# readDir # //########### // Die Funktion "array readDir(string $path){}" gibt alle Files eines // Ordners "$path" in einem Array zurück. function readDir($path) { $name = basename($path); // Name des Ordners if (!$dir = @opendir($path)) // Hier wird der Ordner "$name" geöffnet die ("Der Ordner \"".$name."\" konnte nicht geöffnet werden !"); // Script wird beendet wenn "$dir" false ist $i=0; // Zähler für alle Files while ($file=readdir($dir)) { // Ordner "$name" wird gelesen if (is_dir($path.PATH_SEP.$file) && $file!="." && $file!="..") { // "." und ".." werden gefiltert $files[$i]=$path.PATH_SEP.$file; // Array "$files" beinhaltet alle Files bzw. Pfade $i++; } } closedir($dir); // Hier wird der Ordner wieder geschlossen return $files; // Das Array wird zurückgegeben } //############ //# initRead # //############ function initRead ($dir) { $childs = $dir->getAllChilds($dir->path); foreach ($childs as $elem) { $this->readall($elem); } } //########### //# readAll # //########### function readAll ($elem) { if($childs = $elem->getAllChilds($elem->path)) { foreach ($childs as $elem) { echo $elem->path."<br>"; $this->readAll($elem); } } } }