yana

phpDocumentor v 1.4.0

Class Dir

Description

Manipulate a directory
This class represents a directory. You may use this to get a list of contents, or remove, or create a directory.
  • access: public
Object
   |
   --FileSystemResource
      |
      --Dir
Method Summary
  • Dir Dir (string $path)
  • bool copy (string $destDir, [bool $overwrite = true], [int $mode = 766], [bool $copySubDirs = false], [string $fileFilter = null], [string $dirFilter = null], [bool $useRegExp = false])
  • bool create ([int $mode = 777])
  • bool delete ([bool $isRecursive = false])
  • array dirlist (string $filter)
  • bool exists ()
  • array get ()
  • int|bool(false) getSize ([string $directory = null], [bool $copySubDirs = true], [bool $useCache = true])
  • bool isEmpty ()
  • int length ()
  • bool read ()
  • string toString ()

Methods

constructor
Dir Dir (
string $path
)
List of parameters:
Name Type Description
$path string
Description:
Create a new instance of this class.
copy the directory to some destination
bool copy (
string $destDir, [bool $overwrite = true], [int $mode = 766], [bool $copySubDirs = false], [string $fileFilter = null], [string $dirFilter = null], [bool $useRegExp = false]
)
List of parameters:
Name Type Description
$destDir string destination to copy the file to
$overwrite bool setting this to false will prevent existing files from getting overwritten
$mode int the access restriction that applies to the copied file, defaults to 0766
$copySubDirs bool setting this to true will cause sub-directories to be copied as well
$fileFilter string use this to limit the copied files to a specific extension
$dirFilter string use this to limit the copied directories to those matching the filter
$useRegExp bool set this to bool(true) if you want filters to be treated as a regular expression
Description:
This will create a copy of this directory and its contents on the filesystem. Bool(true) will be returned on success and bool(false) on error.
Since version 2.9.6 you can also use this function with some regular expression. To do so, set $useRegExp to bool(true). It defaults to bool(false). See the PHP manual at php.net/docs for an in-depth introduction on the use of regular expressions.
If you don't want to use regular expressions, you may still use the following wildcards for file- and directory patterns:
  • ? = match 1 symbol, example: f?o, matches 'foo', as well as 'fao'
  • * = match any symbols, example: *foo*, matches 'foo', or 'foobar', or 'barfoo', or 'barfoobar'
  • | = seperate 2 choices, example: foo|bar, matches either 'foo', or 'bar' (but NOT 'foobar')
See the following examples:
  1.  $dir new Dir('foo/');
  2.  
  3.  // copy directory foo/ to destination bar/
  4.  $dir->copy('bar/');
  5.  
  6.  // try to copy to bar2/ but don't overwrite if it already exists
  7.  $dir->copy('bar2/'false);
  8.  
  9.  // copy again and make files write- and executeable
  10.  $dir->copy('bar3/'true777);
  11.  
  12.  // copy to bar4/ and recurse sub-dirs
  13.  $dir->copy('bar4/'true766true);
  14.  
  15.  // copy all *.xml and *.xhtml files to bar3/
  16.  $dir->copy('bar5/'true766true'*.xml|*.xhtml');
  17.  
  18.  // copy all sub-directories, whose names end with 'bar/'
  19.  $dir->copy('bar6/'true766truenull'*bar');
  20.  
  21.  // copy all but directory 'foobar/' (use regular expression)
  22.  $dir->copy('bar7/'true766truenull'/^(?!foobar$)/i'true);
  • since: 2.9.4
  • access: public
create this directory
bool create (
[int $mode = 777]
)
List of parameters:
Name Type Description
$mode int access mode
Description:
Tries to create the directory. Check the developer's cookbook for an example to this function.
  • access: public
  • name: Dir::create()
  • uses: $Dir->create(660)
remove this directory
bool delete (
[bool $isRecursive = false]
)
List of parameters:
Name Type Description
$isRecursive bool triggers wether to remove directories even if they are not empty, default = false
Description:
By option you may choose to also recursivly remove all files and subdirectories inside. Otherwise the directory will only be removed if it is empty.
Returns bool(true) on success and bool(false) on error.
  • access: public
  • uses: $Dir->delete(false)
list contents of a directory
array dirlist (
string $filter
)
List of parameters:
Name Type Description
$filter string
Description:
The argument $filter may contain multiple file extension, use a pipe '|' sign to seperate them. Example: "*.xml|*.html" will find all xml- and html-files
  • access: public
  • uses: $Dir->dirlist('*.cfg')
check if directory exists and is readable
bool exists ()
Description:
Returns bool(true) on success and bool(false) otherwise.
  • access: public

Redefinition of: FileSystemResource::exists()

return list of files within the directory
array get ()
Description:
NOTE: will only return filenames with the path stripped
  • access: public
  • uses: $Dir->get()

Redefinition of: FileSystemResource::get()

get size of directory
int|bool(false) getSize (
[string $directory = null], [bool $copySubDirs = true], [bool $useCache = true]
)
List of parameters:
Name Type Description
$directory string directory name
$copySubDirs bool on / off
$useCache bool on / off
Description:
Returns the size of $directory in bytes.
This function gets the sum of the sizes of all files in a directory.
If $directory is not provided or NULL, the current directory is used. If $copySubDirs is not provided or true, the result will include all subdirectories.
If $useCache is not provided or true, the result is cached for the current directory.
Returns bool(false) if the directory does not exist and issues an E_USER_WARNING.
  • since: 2.8.8
  • access: public
  • uses: $Dir->getSize()
  • uses: $Dir->getSize('foo/bar')
check wether the directory has no contents
bool isEmpty ()
Description:
Returns bool(true) if there are no files that match the current filter and bool(false) if there is at least 1 file that matches.
  • access: public
  • uses: $Dir->isEmpty()
get the number of files inside the directory
int length ()
Description:
This returns a positive integer. Note that this functions counts the files in respect to the currently set file filter. So the number of files reported here and the number in total may vary.
  • access: public
  • uses: $Dir->length()
read contents and put results in cache (filter settings will be applied)
bool read ()
Description:
  • access: public
  • uses: $Dir->read()

Redefinition of: FileSystemResource::read()

return a string representation of this directory
string toString ()
Description:
Returns a string with the contents of this directory. Entries are seperated by line-breaks.
  • access: public
  • uses: $Dir->toString()

Redefinition of: Object::toString()

inherited from base classes

Inherited From FileSystemResource

Inherited From Object

Documentation generated on Sat, 03 Jan 2009 22:22:22 +0100 by phpDocumentor 1.4.0

yana author: Thomas MeyerHomepage: www.yanaframework.net