A collection of often-used file and directory management functions not present in PHP core.
{
"require": {
"yalesov/file-system-manager": "2.*"
}
}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');