Source for file FilesystemTree.class.php
Documentation is available at FilesystemTree.class.php
* For including this file you have to define the constant "CLASSPATH".
* Because every include in the framework depends on the CLASSPATH definition.
* The CLASSPATH means the relative path to the folder that contains the
echo "<h3>You have to define the constant CLASSPATH!</h3>\r\n";
echo "Example: define( 'CLASSPATH', '../path/to/classes/' );\r\n";
require_once( CLASSPATH. "filesystem/FilesystemToolkit.class.php" );
require_once( CLASSPATH. "filesystem/Folder.class.php" );
include_once( CLASSPATH. "filesystem/ImageFiles.class.php" );
* Class to generate Vector object.
include_once CLASSPATH. "data_structures/Vector.class.php";
* A class to managing a filesystemtree.
* @author Daniel Plücken <daniel@debakel.net>
* @license http://www.gnu.org/copyleft/lesser.html
* GNU Lesser General Public License
* @copyright Copyright (c) 2003 Daniel Plücken <daniel@debakel.net>
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
* @author Daniel Plücken <daniel@debakel.net>
* @param string $regExpMatchFiles
* @param string $regExpMatchFolder
* @param boolean $filesize
* @param boolean $handle_known_filetypes For example, images will then put
* into a ImageFiles object, instead
$handle_known_filetypes = false
* Returns the names of folder that this->path contains by an array.
* @author Daniel Plücken <daniel@debakel.net>
$outputArr[] = $this->folder[$i]->getName();
* Returns the names of files that this->path contains by an array.
* @author Daniel Plücken <daniel@debakel.net>
$outputArr[] = $this->files[$i]->getName();
* Returns the path to the folder of this filesystem object.
* @author Daniel Plücken <daniel@debakel.net>
* Returns the foldername of this filsystem tree object.
* @author Daniel Plücken <daniel@debakel.net>
* Returns the file objects of this filesystem tree object in pre-order.
* @author Daniel Plücken <daniel@debakel.net>
foreach ( $this->files as $key => $value )
$out_arr[] = & $this->files[$key];
foreach ( $this->folder as $key => $value )
$tmp_arr = & $this->folder[$key]->getFilesArray();
// array_merge doesn't keep references alive!
foreach ( $tmp_arr as $key2 => $value2 )
$out_arr[] = & $tmp_arr[$key2];
* Builds a tree of the filesystem beginning at $dir.
* @author Daniel Plücken <daniel@debakel.net>
* @param string $dir The base directory from which the filesystem
* @param object $objRef The root object of the tree. It will be this
* @param string $regExpMatchFiles
* @param string $regExpMatchFolder
* @param boolean $filesize With this flag you were able to assign whether
* the filesizes should also stored in the tree.
* @param boolean $handle_known_filetypes For example, images will then put
* into a ImageFiles object, instead
$handle_known_filetypes = false
for ( $i = 0; $i < count( $resArr ); $i++ )
if ( $resArr[$i]["is_dir"] )
$objRef->folder[] = & new Folder(
$tmp_curr = count( $objRef->folder ) - 1;
$objRef->folder[$tmp_curr]->setParentFolder( $objRef );
$dir. "/". $resArr[$i]["name"],
$objRef->folder[$tmp_curr],
if ( !$handle_known_filetypes )
$objRef->files[] = & new Files( $dir, $resArr[$i]["name"] );
$dir. "/". $resArr[$i]["name"]
$objRef->files[] = & new Files(
$tmp_curr = count( $objRef->files ) - 1;
$objRef->files[$tmp_curr]->setFilesize( $resArr[$i]["size"] );
$objRef->files[$tmp_curr]->setParentFolder( $objRef );
* Search an Files object in the tree that is equal to the given one. The
* two File objects will be accounted as equal, if the the filenames and
* pathes match each other.
* @author Daniel Plücken <daniel@debakel.net>
* @param string $f_obj The object to find.
* @param string $folder_obj The reference used to dig in the filesystem
* tree. This variable has to be initialized
function &findFile( &$f_obj, &$folder_obj /* = $this */ )
for ( $i = 0; $i < count( $folder_obj->files ); $i++ )
if ( $f_obj->equals( $folder_obj->files[$i] ) )
# ImageFiles object found!
return $folder_obj->files[$i];
for ( $i = 0; $i < count( $folder_obj->folder ); $i++ )
$return_obj = & $this->findFile( $f_obj, $folder_obj->folder[$i] );
# ImageFiles object found in depth!
* Builds and returns a Vector from the filesystem trees. That means that
* all files will be in a list, so for example you can operate with next()-
* and prev()-function to navigate in that list.
* @author Daniel Plücken <daniel@debakel.net>
* @param string $folder_obj The reference used to dig in the filesystem
* tree. This variable has to be initialized
for ( $i = 0; $i < count( $folder_obj->files ); $i++ )
$vec_obj->add( $folder_obj->files[$i] );
for ( $i = 0; $i < count( $folder_obj->folder ); $i++ )
* Sends a dirty formatted list of this filesystem to the browser.
* @author Daniel Plücken <daniel@debakel.net>
echo $this->folder[$i]->getName(). "<br>\n";
$this->folder[$i]->echoNameQueque();
echo $this->files[$i]->getName(). "<br>\n";
} // END of class FilesystemTree
|