Sitellite Application Framework
Class Tree         Index         All Elements

Class: Dir

Source Location: Program_Root/File/Directory.php

Class Overview

Directory
   |
   --Dir

Dir is basically a wrapper class around PHP's internal Directory


Author(s)

Version

  • 1.8, 2002-08-23, $Id: Directory.php,v 1.2 2005/07/06 15:30:56 lux Exp $

Copyright

  • Copyright (C) 2001-2003, Simian Systems Inc.

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 83]
Dir is basically a wrapper class around PHP's internal Directory

class which provides a little more functionality. It really only defines an additional method read_all(), which allows you to retrive directory lists sorted by a number of properties, including alphabetically (by name), by date (most recently modified first), and by size (largest on top).

New in 1.2:

  • find () method will search through directories (recusion is optional) for files based on patterns, which are parsed by the matches () method.
New in 1.4:
  • find_in_files() method will search through directories (recursion is optional) for files whose contents contain a specified string or pattern, which relies on the File class for the content evaluation.
New in 1.6:
  • build() method will build a directory structure for you recursively if any parts of the path do not exist.
  • rmdir_recursive() method will remove a directory and all of its contents.
New in 1.8:
  • Added an open() method, so that you can reuse the same Directory object.
Note: All the other methods are identical to PHP's internal Directory class.


1 <?php
2
3 $dir = new Dir ("/path/to/dir/you/want");
4
5 // read the directory in the traditional method, where sorting must be
6 // done yourself...
7 while ($file = $dir->read ()) {
8 // do something with $file
9 }
10
11 $dir->rewind ();
12
13 // now let's do it with the new read_all() method, and sort by size
14 $list = $dir->read_all ("size");
15 foreach ($list as $file) {
16 // do something with $file
17 }
18
19 $dir->close ();
20
21 ? >




Tags:

access:  public
version:  1.8, 2002-08-23, $Id: Directory.php,v 1.2 2005/07/06 15:30:56 lux Exp $
license:  http://www.sitellite.org/index/license
copyright:  Copyright (C) 2001-2003, Simian Systems Inc.
author:  John Luxford <mailto:lux@simian.ca>


[ Top ]


Class Variables

$handle =  ""

[line 90]

Contains the handle of the currently open directory.



Tags:

access:  public

Type:   mixed


[ Top ]

$path =  ""

[line 98]

Contains the path provided to the currently open directory.



Tags:

access:  public

Type:   mixed


[ Top ]



Class Methods


constructor Dir [line 116]

Dir Dir( [string $dir_string = ""])

Constructor method. Opens the specified directory if one is provided.



Tags:

access:  public


Parameters:

string   $dir_string  

[ Top ]

method build [line 380]

boolean build( string $path, [integer $mode = 0700])

Takes a directory path and builds each level if they don't exist.

For example: calling Dir::build('sitellite/mod/newmodule/pix') while in the base directory of your site would change directories to sitellite/mod then call mkdir('newmodule'), chdir('newmodule'), and finally mkdir('pix'), before decending back to the directory you started in. Note: This method does not affect the current working directory. Also note that the $mode must be specified as a 4-digit octal value. See php.net/mkdir for more information on $mode values.




Tags:

access:  public


Parameters:

string   $path  
integer   $mode  

[ Top ]

method close [line 200]

void close( )

Closes the current directory.



Tags:

access:  public


[ Top ]

method fetch [line 448]

array fetch( string $path, [mixed $skipDots = false])

Fetches all the files in a directory in a single command, ie. $files = Dir::fetch ('foo/bar');



Tags:

return:  files
access:  public


Parameters:

string   $path  

[ Top ]

method find [line 291]

array find( [string $pattern = '*'], string $basedir, [boolean $recursive = 0])

Searches a directory or directories (recursively) for a file that matches a given pattern.



Tags:

access:  public


Parameters:

string   $pattern  
string   $basedir  
boolean   $recursive  

[ Top ]

method findInFiles [line 330]

array findInFiles( string $string, string $basedir, [boolean $recursive = 0], [boolean $regex = 0])

Searches a directory or directories (recursively) for a file that contains a given string or pattern. Note: this method requires the saf.File class.



Tags:

access:  public


Parameters:

string   $string  
string   $basedir  
boolean   $recursive  
boolean   $regex  

[ Top ]

method find_in_files [line 361]

void find_in_files( mixed $string, mixed $basedir, [mixed $recursive = 0], [mixed $regex = 0])

Deprecated. Use findInFiles() instead.

Exists for backward-compatibility.




[ Top ]

method getStruct [line 476]

array getStruct( string $path)

Returns the "structure" of the filesystem below the specified path.

This is a list of sub-directories, recursively.




Tags:

return:  files
access:  public


Parameters:

string   $path  

[ Top ]

method matches [line 270]

boolean matches( [string $pattern = '*'], string $file)

Compares a file name to a pattern string, which may contain simple * wildcards.



Tags:

access:  public


Parameters:

string   $pattern  
string   $file  

[ Top ]

method open [line 129]

void open( string $dir_string)

Opens the specified directory.



Tags:

access:  public


Parameters:

string   $dir_string  

[ Top ]

method read [line 180]

string read( )

Read the contents of the directory and return them one at a time.



Tags:

access:  public


[ Top ]

method readAll [line 152]

array readAll( [string $sorting_method = "alphabetical"])

Read and sort the contents of the directory and return them as an array.

$sorting_method can be either 'alphabetical' (the default), 'date', or 'size'.

Note: read_all() does not remove any entries from this list, such as . and ..




Tags:

access:  public


Parameters:

string   $sorting_method  

[ Top ]

method read_all [line 169]

void read_all( [mixed $sorting_method = "alphabetical"])

Deprecated. Use readAll() instead.

Exists for backward-compatibility.




[ Top ]

method rewind [line 190]

void rewind( )

Rewinds the internal cursor for the purpose of re-reading the directory contents.



Tags:

access:  public


[ Top ]

method rmdirRecursive [line 411]

boolean rmdirRecursive( [string $path = ''])

Removes a directory and all of its contents.



Tags:

access:  public


Parameters:

string   $path  

[ Top ]

method rmdir_recursive [line 435]

void rmdir_recursive( [mixed $path = ''])

Deprecated. Use rmdirRecursive() instead.

Exists for backward-compatibility.




[ Top ]


Copyright © 2007, SIMIAN systems Inc.
All rights reserved. Privacy policy
Documentation generated on Tue, 13 Feb 2007 17:17:19 -0600 by Sitellite AppDoc and phpDocumentor 1.2.2