A collection of file and directory management functions.
PHP
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src/Yalesov/FileSystemManager
test
.gitignore
.travis.yml
README.md
composer.json

README.md

Yalesov\FileSystemManager

Build Status

A collection of often-used file and directory management functions not present in PHP core.

Installation

Composer:

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

Usage

Recursively iterate the directory foo, listing all files (child-last):

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

Recursively iterate the directory foo, listing all directories (child-first):

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

Recursive rmdir: remove the directory foo along with all child directories and files

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

Recursive copy: copy the directory foo to bar along with all child directories and files

Warning: this function overwrites existing files

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

rcopy will copy into existing directories if they already exist. By default, it will create non-existent directories with permission 0755. You can change this by specifying the third parameter:

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

Recursive chmod: chmod the directory foo to 0755, along with all child directories and files

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

Recursive chown: chown the directory foo to www-data, along with all child directories and files

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

Recursive chgrp: chgrp the directory foo to www-data, along with all child directories and files

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