heartsentwined/file-system-manager

一组文件和目录管理功能。

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

This package is not auto-updated.

Last update: 2024-09-14 11:55:51 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');