File: system/dependencies/cakephp/filesystem/README.md

Recommend this page to a friend!
  Classes of Dimitri Sitchet  >  dframework  >  system/dependencies/cakephp/filesystem/README.md  >  Download  
File: system/dependencies/cakephp/filesystem/README.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: dframework
Framework to build PHP applications
Author: By
Last change:
Date: 5 months ago
Size: 1,282 bytes
 

Contents

Class file image Download

Total Downloads License

CakePHP Filesystem Library

The Folder and File utilities are convenience classes to help you read from and write/append to files; list files within a folder and other common directory related tasks.

Basic Usage

Create a folder instance and search for all the .ctp files within it:

use Cake\Filesystem\Folder;

$dir = new Folder('/path/to/folder');
$files = $dir->find('.*\.ctp');

Now you can loop through the files and read from or write/append to the contents or simply delete the file:

foreach ($files as $file) {
    $file = new File($dir->pwd() . DIRECTORY_SEPARATOR . $file);
    $contents = $file->read();
    // $file->write('I am overwriting the contents of this file');
    // $file->append('I am adding to the bottom of this file.');
    // $file->delete(); // I am deleting this file
    $file->close(); // Be sure to close the file when you're done
}

Documentation

Please make sure you check the official documentation

For more information send a message to info at phpclasses dot org.