Path

ez components / documentation / api reference / 2007.1 / file


eZ Components 2007.1

File

[ Tutorial ] [ Class tree ] [ Element index ] [ ChangeLog ] [ Credits ]

Introduction

The File component currently contains one class, providing a few handy file system operations that are missing from PHP.

Class overview

ezcFile is the only class in this component. It provides two static methods: ezcFile::findRecursive() and ezcFile::removeRecursive().

Usage

Finding files recursively

This example shows how to use the ezcFile::findRecursive() method:

  1. <?php
  2. require 'tutorial_autoload.php';
  3. 
  4. $data ezcFile::findRecursive(
  5.     "/dat/dev/ezcomponents",
  6.     array( '@src/.*_autoload.php$@' ),
  7.     array( '@/autoload/@' )
  8. );
  9. var_dump$data );
 10. 
 11. ?>

The code in this example searches for files in the /dat/dev/ezcomponents directory. It will only include files that match all patterns in the $includeFilters array (the second parameter). Files that match any of the patterns in the $excludeFilters array (the third parameter) will not be returned.

In other words, the code above searches for files in the dat/dev/ezcomponents directory, which are in the src/ directory and end with _autoload.php, except for files that are in the /autoload/ directory.

Removing directories recursively

This example shows how to use the ezcFile::removeRecursive() method:

  1. <?php
  2. require 'tutorial_autoload.php';
  3. 
  4. ezcFile::removeRecursive'/dat/dev/ezcomponents/trash' );
  5. 
  6. ?>

This code simply removes the directory /dat/dev/ezcomponents/trash and all of its files and sub-directories.

Warning: Use this function with care, as it has the potential to erase everything that the current user has access to.

More information

For more information, see the ezcFile API documentation.

Last updated: Thu, 01 Nov 2007