yalesov/file-system-manager

一系列文件和目录管理功能。

v2.0.6 2016-07-06 12:20 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:53:12 UTC


README

Build Status

收集了PHP核心中不存在的常用文件和目录管理功能。

安装

Composer:

{
  "require": {
    "yalesov/file-system-manager": "2.*"
  }
}

用法

递归遍历目录foo,列出所有文件(子文件最后)

use \Yalesov\FileSystemManager\FileSystemManager;
foreach (FileSystemManager::fileIterator('foo') as $file) {
  echo $file; // /path/to/file
}

递归遍历目录foo,列出所有目录(子目录首先)

use \Yalesov\FileSystemManager\FileSystemManager;
foreach (FileSystemManager::dirIterator('foo') as $dir) {
  echo $dir; // /path/to/child/dir
}

递归rmdir:删除目录foo及其所有子目录和文件

use \Yalesov\FileSystemManager\FileSystemManager;
FileSystemManager::rrmdir('foo');

递归copy:将目录foo复制到bar,包括所有子目录和文件

警告:此函数会覆盖现有文件

use \Yalesov\FileSystemManager\FileSystemManager;
FileSystemManager::rcopy('foo', 'bar');

rcopy会复制到已存在的目录中。默认情况下,它将创建不存在目录,权限为0755。您可以通过指定第三个参数来更改此设置

FileSystemManager::rcopy('foo', 'bar', 0777);

递归chmod:将目录foo的权限设置为0755,包括所有子目录和文件

use \Yalesov\FileSystemManager\FileSystemManager;
FileSystemManager::rchmod('foo', 0755);

递归chown:将目录foo的所有者设置为www-data,包括所有子目录和文件

use \Yalesov\FileSystemManager\FileSystemManager;
FileSystemManager::rchown('foo', 'www-data');

递归chgrp:将目录foo的组设置为www-data,包括所有子目录和文件

use \Yalesov\FileSystemManager\FileSystemManager;
FileSystemManager::rchown('foo', 'www-data');