1. Go to this page and download the library: Download tarsana/filesystem library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tarsana / filesystem example snippets
// Create a Filesystem instance given a root path
$fs = new Tarsana\Filesystem('path/to/fs/root/directory');
if ($fs->isFile('path'))
if ($fs->isDir('path'))
if ($fs->isAny('path'))
if ($fs->areFiles(['path1', 'path2', 'path3']))
if ($fs->areDirs(['path1', 'path2', 'path3']))
if ($fs->areAny(['path1', 'path2', 'path3']))
$fs->whatIs('path-pattern')
$collection = $fs->find('pattern'); // a Collection instance
foreach ($collection->asArray() as $fileOrDir) {
// Handle the file or directory
}
$collection->count(); // number of elements
$collection->add($fs->file('path/to/file')); // add new element to the collection
$collection->contains('path'); // checks if the collection contains an element with that path
$collection->remove('path'); // remove the element having the path from the collection
$collection->files(); // a new collection containing only files
$collection->dirs(); // a new collection containing only directories
$collection->first(); // the first element
$collection->last(); // the last element
$collection->paths(); // array of paths of the files and directories
$collection->names(); // array of names of the files and directories
$file = $fs->file('path/to/file');
$file = $fs->file('path/to/file', true);
$files = $fs->files([
'path/to/file1',
'path/to/file2',
'path/to/file3'
]); // specify the second argument as true if you want missing files to be created
foreach ($files->asArray() as $file) {
// Handle the file
}
$file->name(); // get the name
$file->name('new-name.txt'); // renaming the file
$file->path(); // get the absolute path
$file->path('new/absolute/path'); // moving the file
$file->content(); // reading the content
$file->content('new content'); // writing to the file
$file->append('additional content'); // add content to the file
$file->hash(); // get the md5 hash of the content
$file->extension(); // get the extension (like "txt" or "php")
$file->perms(); // get the file permissions as string (like "0755")
$file->isWritable(); // check if the file is writable
$file->isExecutable(); // check if the file is executable
$copy = $file->copyAs('absolute/path/to/file-copy'); // Copy the file
$file->remove(); // Remove the file
$dir = $fs->dir('path/to/dir'); // throws exception if the directory not found
$dir = $fs->dir('path/to/dir', true); // creates the directory if not found
$dirs = $fs->dirs([
'path/to/file1',
'path/to/file2',
'path/to/file3'
]); // a collection containing directories
$dir->name(); // get the name
$dir->name('new-name'); // renaming the directory
$dir->path(); // get the absolute path
$dir->path('new/absolute/path'); // moving the directory
$dir->perms(); // get the directory permissions as string (like "0755")
$copy = $dir->copyAs('absolute/path/to/dir-copy'); // Copy the directory
$dir->remove(); // Remove the directory
$dir->fs(); // get a Filesystem instance having this directory as root
// Default constructor uses STDOUT by default
$stdout = new Writer;
// Any writable resource can be used
$res = fopen('temp.txt', 'w');
$out = Writer($res);
// Or just give the path
$out = Writer('php://memory');
// Writing content
$out->write('Hello ')->write('World !');
// Writes "Hello World !" to the resource
$out->writeLine('Hi');
// Writes "Hi".PHP_EOL to the resource
// The resource is closed when the $out object is destructed
// But you can still close it before
$out->close();
$stdin = new Reader; // when no parameter is given, it uses STDIN by default
$stdin->read(); // reads the whole content of STDIN
$stdin->read(100); // reads 100 bytes from STDIN
$stdin->readUntil(' '); // reads until the first ' ' (space) or EOF
$stdin->readLine(); // reads until PHP_EOL or EOF
// If the STDIN is empty and we do
$stdin->blocking(false)->read();
// This will return immediately an empty string; no blocking !
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.