PHPackages                             tarsana/filesystem - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. tarsana/filesystem

ActiveLibrary[File &amp; Storage](/categories/file-storage)

tarsana/filesystem
==================

Tarsana Filesystem library

2.0.1(8y ago)4111MITPHP

Since Dec 16Pushed 6mo ago3 watchersCompare

[ Source](https://github.com/tarsana/filesystem)[ Packagist](https://packagist.org/packages/tarsana/filesystem)[ RSS](/packages/tarsana-filesystem/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (8)Dependencies (1)Versions (10)Used By (0)

Tarsana Filesystem Package
==========================

[](#tarsana-filesystem-package)

[![Build Status](https://camo.githubusercontent.com/6459c3fe3e5c5ab30f738cdf4eb50f63894dc605c3586b62b906fbfed7294d8f/68747470733a2f2f7472617669732d63692e6f72672f74617273616e612f66696c6573797374656d2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/tarsana/filesystem)[![Coverage Status](https://camo.githubusercontent.com/7cabe75f2d61eca9c4ef66da71df4ed0747691e39655c641d910395732365a86/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f74617273616e612f66696c6573797374656d2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/tarsana/filesystem?branch=master)[![Donate](https://camo.githubusercontent.com/604e3db9c8751116b3f765aad0353ec7ded655bbe8aaacbc38d8c4a6b784b3ed/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f6e6174652d50617950616c2d677265656e2e737667)](https://paypal.me/webneat)[![Software License](https://camo.githubusercontent.com/f251623e510f5909f16ae3f4e6e548dac11340b9fde1a99be26b015b39272c00/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c6174)](https://github.com/tarsana/filesystem/blob/master/LICENSE)

Simple classes to handle Filesystem operations.

Installation
------------

[](#installation)

Install it using composer

```
composer require tarsana/filesystem

```

Handeling Files and Directories
-------------------------------

[](#handeling-files-and-directories)

The `Filesystem` class was designed to be used easily and support call chaining which makes the code more readable.

```
// Create a Filesystem instance given a root path
$fs = new Tarsana\Filesystem('path/to/fs/root/directory');
```

### Checking Paths

[](#checking-paths)

Maybe you need to check if a specific path is a file

```
if ($fs->isFile('path'))
```

or a directory

```
if ($fs->isDir('path'))
```

or you just want to know it exists, no matter it's a file or directory

```
if ($fs->isAny('path'))
```

What if you need to check multiple paths at once ?

```
if ($fs->areFiles(['path1', 'path2', 'path3']))
if ($fs->areDirs(['path1', 'path2', 'path3']))
if ($fs->areAny(['path1', 'path2', 'path3']))
```

But what if you want to know the type of a path without having to do multiple checks ?

```
$fs->whatIs('path-pattern')
```

You can use wildcard pattern as argument to this function and the result will be:

- `'file'`: if a single file corresponds to the pattern.
- `'dir'`: if a single directory corresponds to the pattern.
- `'collection'`: if multiple files and/or directories correspond to the pattern.
- `'nothing'`: if nothing corresponds to the pattern.

### Finding Files and Directories

[](#finding-files-and-directories)

Now what if you want to get all files and directories corresponding to a pattern ?

```
$collection = $fs->find('pattern'); // a Collection instance

foreach ($collection->asArray() as $fileOrDir) {
	// Handle the file or directory
}
```

You can also manipulate the collection

```
$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
```

### Handling Files

[](#handling-files)

Well, to handle a file, you should get it first

```
$file = $fs->file('path/to/file');
```

Notice that this will throw an exception if the file is not found. If you want to create it when missing; specify `true` in the second argument

```
$file = $fs->file('path/to/file', true);
```

You can also get or create multiple files at once

```
$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
}
```

Now that you have the file, you can play with it

```
$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
```

Notice that all setters return the same instance to enable call chaining.

### Handling Directories

[](#handling-directories)

Just like the file, you can get a directory like that

```
$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
```

Having a directory, you can play with it

```
$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
```

Notice that all setters return the same instance to enable call chaining.

Reading &amp; Writing to Resources
----------------------------------

[](#reading--writing-to-resources)

### Writer

[](#writer)

`Tarsana\Filesystem\Resource\Writer` gives the possibility to write content to any resource.

```
// 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();
```

### Reader

[](#reader)

`Tarsana\Filesystem\Resources\Reader` gives the possibility to read content from any resource. Constructors are the same as `Writer` but the default resource is `STDIN`.

```
$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 !
```

### Buffer

[](#buffer)

`Tarsana\Filesystem\Resource\Buffer` is a Reader and Writer at the same time. If no resource is given, it uses `php://memory` to store content.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance47

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~112 days

Recently: every ~146 days

Total

8

Last Release

3016d ago

Major Versions

1.2.0 → 2.0.0-alpha2017-08-25

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2133333?v=4)[Amine Ben hammou](/maintainers/webNeat)[@webNeat](https://github.com/webNeat)

---

Top Contributors

[![webNeat](https://avatars.githubusercontent.com/u/2133333?v=4)](https://github.com/webNeat "webNeat (51 commits)")

---

Tags

filesysteminputmockingoutputphpreaderresourcewriter

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tarsana-filesystem/health.svg)

```
[![Health](https://phpackages.com/badges/tarsana-filesystem/health.svg)](https://phpackages.com/packages/tarsana-filesystem)
```

###  Alternatives

[knplabs/gaufrette

PHP library that provides a filesystem abstraction layer

2.5k39.8M123](/packages/knplabs-gaufrette)[google/cloud-storage

Cloud Storage Client for PHP

34390.8M125](/packages/google-cloud-storage)[illuminate/filesystem

The Illuminate Filesystem package.

15261.6M2.6k](/packages/illuminate-filesystem)[superbalist/flysystem-google-storage

Flysystem adapter for Google Cloud Storage

26320.6M30](/packages/superbalist-flysystem-google-storage)[creocoder/yii2-flysystem

The flysystem extension for the Yii framework

2931.7M62](/packages/creocoder-yii2-flysystem)[flowjs/flow-php-server

PHP library for handling chunk uploads. Works with flow.js html5 file uploads.

2451.6M15](/packages/flowjs-flow-php-server)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
