Recommend this page to a friend! |
Download .zip |
Info | Documentation | View files (12) | Download .zip | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2016-02-18 (8 months ago) | Not yet rated by the users | Total: 180 This week: 1 | All time: 7,970 This week: 1,047 |
Version | License | PHP version | Categories | |||
filesystem-helper 0.1 | GNU General Publi... | 5 | PHP 5, Files and Folders |
Description | Author | ||||||||
This class can manipulate and search files and directories. Recommendations Find Large Files list files and folders |
|
A helper class for filesystem operations
This class uses PHP Iterators in order to dynamically and stably provide filesystem operation access.
I tried to make this as fluid and dynamic as possible. Strangely, I couldn't seem to find any presently existing dynamic classes for file io operations, so I spent a couple hours coding this up. Please DO report possible errors.
I think the most important note is that Iterators do not take up massive amounts of memory like arrays do provided with glob and other methods. This class uses Iterators. Thus, we have speed + scalability.
Some might wonder why I did not implement glob methods. Two very good reasons led me to avoid glob: 1. Glob returns all results in an array, and has a relatively small limit(10,000 results or so). 2. Regex covers what glob provides, + more
That's all. Enjoy.
The following methods are provided:
`
public static function create($folder, $mode=0777, $recursive=true)`
`
public static function read($file)`
`
public static function write($file, $contents, $flag='w+')`
`
public static function searchR($folder, $pattern=null, $depth=-1, $flags=RecursiveIteratorIterator::SELF_FIRST)`
`
public static function search($folder, $pattern=null)`
`
public static function deleteR($folder, $pattern=null, $depth=-1)`
`
public static function delete($folder_or_file, $pattern=null)`
The class can be used standalone, however it's recommended to install via Composer:
composer require iautomation/filesystem-helper
If using Composer, just do something like:
use \FilesystemHelper\FilesystemHelper;
include 'path/to/vendor/autoload.php';
FilesystemHelper::deleteR('test', null); // DELETE TEST AND ALL CONTENTS!!
Otherwise, simply include the class:
use \FilesystemHelper\FilesystemHelper;
include 'path/to/FilesystemHelper.php';
FilesystemHelper::deleteR('test', null); // DELETE TEST AND ALL CONTENTS!!
// create test folder
FilesystemHelper::create('test');
// write to test/test.php
FilesystemHelper::write('test/test.php', 'test123');
// get file contents
echo FilesystemHelper::read('test/a.php');
// get all direct folders and files under test
foreach(FilesystemHelper::search('test') as $file){
echo $file."\n";
}
// get all folders and files under test recursively
foreach(FilesystemHelper::searchR('test') as $file){
echo $file."\n";
}
// get all direct files under test with the php extension using regex
foreach(FilesystemHelper::search('test', '/.*.php/') as $file){
echo $file."\n";
}
// get all recursive files under test with the php extension using regex
foreach(FilesystemHelper::searchR('test', '/.*.php/') as $file){
echo $file."\n";
}
// get all directories under test
foreach(FilesystemHelper::searchR('test') as $file){
if($file->isDir())
echo $file."\n";
}
// get all files under test
foreach(FilesystemHelper::searchR('test') as $file){
if($file->isFile())
echo $file."\n";
}
// get all folders and files under test listed "backwards". This is particularly useful when deleting
$iter = FilesystemHelper::searchR('test', null, -1, RecursiveIteratorIterator::CHILD_FIRST);
foreach($iter as $file){
echo $file."\n";
}
/
DELETE FUNCTIONS ARE NOT FORGIVING. USE WITH CAUTION
*/
// delete all folders and files under test recursively
FilesystemHelper::deleteR('test', null);
// delete all direct folders and files under test
FilesystemHelper::delete('test', null);
// delete all recursive files under test with the php extension using regex
FilesystemHelper::deleteR('test', '/.*.php/', 1);
// delete the test/test.php file
FilesystemHelper::delete('test/test.php');
Files |
File | Role | Description | ||
---|---|---|---|---|
src (1 directory) | ||||
vendor (1 file, 1 directory) | ||||
composer.json | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
README.md | Doc. | Documentation |
Files | / | vendor | / | composer |
File | Role | Description |
---|---|---|
autoload_classmap.php | Appl. | Application script |
autoload_namespaces.php | Appl. | Application script |
autoload_psr4.php | Appl. | Application script |
autoload_real.php | Appl. | Application script |
ClassLoader.php | Appl. | Application script |
installed.json | Data | Auxiliary data |
LICENSE | Lic. | License text |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.