cakephp/filesystem

CakePHP 文件系统便利类库,帮助您处理文件和文件夹。

4.5.7 2023-07-29 16:24 UTC

This package is auto-updated.

Last update: 2024-09-21 03:05:10 UTC


README

Total Downloads License

此包已弃用。

CakePHP 文件系统库

文件夹和文件实用工具是便利类,帮助您读取和写入/追加文件内容;列出文件夹内的文件以及其他常见目录相关任务。

基本用法

创建一个文件夹实例并搜索其内的所有.php文件

use Cake\Filesystem\Folder;

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

现在您可以遍历文件并从文件中读取或写入/追加内容,或者简单地删除该文件

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
}

文档

请确保您查阅了官方文档