PHPackages                             neunerlei/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. neunerlei/filesystem

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

neunerlei/filesystem
====================

A static wrapper around the symfony filesystem with additional methods for extra flavor

6.1.0(3mo ago)02.9k[1 PRs](https://github.com/Neunerlei/filesystem/pulls)4Apache-2.0PHPCI passing

Since Mar 12Pushed 1mo ago1 watchersCompare

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

READMEChangelogDependencies (3)Versions (16)Used By (4)

File System
===========

[](#file-system)

This package contains a static wrapper around the [symfony file system component](https://symfony.com/doc/current/components/filesystem.html) with some additional features. Since version 5.3 it also contains an extension for the `Path` utility, and replaces [Neunerlei/path-util](https://github.com/Neunerlei/path-util).

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

[](#installation)

Install this package using composer:

```
composer require neunerlei/filesystem

```

Filesystem Utility
------------------

[](#filesystem-utility)

The filesystem class can be found at `Neunerlei\FileSystem\Fs`.

#### getFs()

[](#getfs)

Returns the singleton instance of the symfony file system class

```
use Neunerlei\FileSystem\Fs;
// Access the symfony methods as you would normally
Fs::getFs()->isAbsolutePath("...");
```

#### copy()

[](#copy)

Copies a file **or a directory**. If the target file is older than the origin file, it's always overwritten.

```
use Neunerlei\FileSystem\Fs;
// Copy a file
Fs::copy("/path/file.txt", "/anotherPath/file.txt");

// Copy / mirror a directory
Fs::copy("/path/to/directory", "/anotherPath");
```

#### mkdir()

[](#mkdir)

Creates a directory recursively.

```
use Neunerlei\FileSystem\Fs;
Fs::mkdir("/create/directory/recursively");
```

#### exists()

[](#exists)

Checks the existence of files or directories.

```
use Neunerlei\FileSystem\Fs;
Fs::exists("/check/existence.txt"); // TRUE|FALSE
```

#### isReadable()

[](#isreadable)

Tells whether a file or list of files exists and is readable.

```
use Neunerlei\FileSystem\Fs;
Fs::isReadable("/check/readability.txt"); // TRUE|FALSE
```

#### isWritable()

[](#iswritable)

Tells whether a file or list of files exists and is writable.

```
use Neunerlei\FileSystem\Fs;
Fs::isWritable("/check/writeability.txt"); // TRUE|FALSE
```

#### isFile()

[](#isfile)

Tells whether a file or list of paths exists and contains only files

```
use Neunerlei\FileSystem\Fs;
Fs::isFile("/check/if/fileExists.txt"); // TRUE|FALSE
```

#### isDir()

[](#isdir)

Tells whether a file or list of paths exists and contains only directories

```
use Neunerlei\FileSystem\Fs;
Fs::isDir("/check/if/directoryExists.txt"); // TRUE|FALSE
```

#### touch()

[](#touch)

Sets access and modification time of file.

NOTE: You can also pass DateTime objects as timestamps!

```
use Neunerlei\FileSystem\Fs;
Fs::touch("/check/touchy.txt", new DateTime());
```

#### remove()

[](#remove)

Removes files or directories.

```
use Neunerlei\FileSystem\Fs;
Fs::remove("/path/to/remove.txt");
```

#### flushDirectory()

[](#flushdirectory)

Removes all contents from a given directory without removing the element itself.

```
use Neunerlei\FileSystem\Fs;
Fs::flushDirectory("/path/to/clean");
```

#### getDirectoryIterator()

[](#getdirectoryiterator)

Helper to create a directory iterator either for a single folder or recursively. Dots will automatically be skipped. It can also find only files matching a regular expression. By default the folder will come after the children, which can be toggled using the options.

```
use Neunerlei\FileSystem\Fs;
// Traverse the direct children of a directory
Fs::getDirectoryIterator("/path/to/iterate");

// Traverse a directory recursively
Fs::getDirectoryIterator("/path/to/iterate", true);

// Filter by regex
Fs::getDirectoryIterator("/path/to/iterate", true, ["regex" => "/\.txt$/"]);

// Return the folders before returning the children
Fs::getDirectoryIterator("/path/to/iterate", true, ["dirFirst"]);
```

#### rename()

[](#rename)

Allows you to rename a file or directory

```
use Neunerlei\FileSystem\Fs;
Fs::rename("/path/a", "/path/b");
```

#### getPermissions()

[](#getpermissions)

Returns the unix file permissions for a given file like "0777" as a string.

```
use Neunerlei\FileSystem\Fs;
Fs::getPermissions("/file/with/full/access.txt"); // "0777"
Fs::getPermissions("/file/with/read/access.txt"); // "0222"
```

#### setPermissions()

[](#setpermissions)

Can be used to set the unix permissions for a file or folder.

```
use Neunerlei\FileSystem\Fs;
Fs::setPermissions("/file/path.txt", 0222);
Fs::setPermissions("/directory", 0222);
```

#### getOwner()

[](#getowner)

Returns the numeric unix user id for the given file or folder

```
use Neunerlei\FileSystem\Fs;
Fs::getOwner("/file/access.txt"); // 1000
```

#### setOwner()

[](#setowner)

Can be used to update the owner of a given file or folder

```
use Neunerlei\FileSystem\Fs;
Fs::setOwner("/file/access.txt", 1001);
```

#### getGroup()

[](#getgroup)

Returns the numeric unix user group for the given filename

```
use Neunerlei\FileSystem\Fs;
Fs::getGroup("/file/access.txt"); // 5
```

#### setGroup()

[](#setgroup)

Can be used to update the group of a given file or folder

```
use Neunerlei\FileSystem\Fs;
Fs::setGroup("/file/access.txt", 10);
```

#### readFile()

[](#readfile)

A wrapper around file\_get\_contents which reads the contents, but handles unreadable or non existing files with speaking exceptions.

```
use Neunerlei\FileSystem\Fs;
$content = Fs::readFile("/file/access.txt");
```

#### readFileAsLines()

[](#readfileaslines)

A wrapper around file() which handles non existing, or unreadable files with speaking exceptions.

```
use Neunerlei\FileSystem\Fs;
$lines = Fs::readFileAsLines("/file/access.txt");
```

#### writeFile()

[](#writefile)

Writes the given content into a file on your file system.

```
use Neunerlei\FileSystem\Fs;
Fs::writeFile("/file.txt", "myContent");
```

#### appendToFile()

[](#appendtofile)

Appends content to an existing file. By default all content will be added on a new line.

```
use Neunerlei\FileSystem\Fs;

// Add "myContent" as a new line to the file
Fs::appendToFile("/file.txt", "myContent");

// Add "myContent" directly at the end
Fs::appendToFile("/file.txt", "myContent", false);
```

Path Utility
------------

[](#path-utility)

The filesystem class can be found at `Neunerlei\FileSystem\Path`.

```
use Neunerlei\FileSystem\Path;

// These methods are added by this fork
// ==========================================================
echo Path::unifySlashes("\\foo/bar\\baz");
// => /foo/bar/baz (on linux) or \foo\bar\baz (on windows)

echo Path::unifyPath("\\foo/bar\\baz");
// => /foo/bar/baz/ (on linux) or \foo\bar\baz\ (on windows)

echo Path::classBasename(\Neunerlei\FileSystem\Path::class);
// => Path

echo Path::classNamespace(\Neunerlei\FileSystem\Path::class);
// => Neunerlei\FileSystem

$link = Path::makeUri();
// => Returns a new Uri object -> See "URI" Section for details.

// Those methods were already in the base implementation
// ==========================================================
echo Path::canonicalize('/var/www/vhost/webmozart/../config.ini');
// => /var/www/vhost/config.ini

echo Path::canonicalize('C:\Programs\Webmozart\..\config.ini');
// => C:/Programs/config.ini

echo Path::canonicalize('~/config.ini');
// => /home/webmozart/config.ini

echo Path::makeAbsolute('config/config.yml', '/var/www/project');
// => /var/www/project/config/config.yml

echo Path::makeRelative('/var/www/project/config/config.yml', '/var/www/project/uploads');
// => ../config/config.yml

$paths = array(
    '/var/www/vhosts/project/httpdocs/config/config.yml',
    '/var/www/vhosts/project/httpdocs/images/banana.gif',
    '/var/www/vhosts/project/httpdocs/uploads/../images/nicer-banana.gif',
);

Path::getLongestCommonBasePath($paths);
// => /var/www/vhosts/project/httpdocs

Path::getFilename('/views/index.html.twig');
// => index.html.twig

Path::getFilenameWithoutExtension('/views/index.html.twig');
// => index.html

Path::getFilenameWithoutExtension('/views/index.html.twig', 'html.twig');
Path::getFilenameWithoutExtension('/views/index.html.twig', '.html.twig');
// => index

Path::getExtension('/views/index.html.twig');
// => twig

Path::hasExtension('/views/index.html.twig');
// => true

Path::hasExtension('/views/index.html.twig', 'twig');
// => true

Path::hasExtension('/images/profile.jpg', array('jpg', 'png', 'gif'));
// => true

Path::changeExtension('/images/profile.jpeg', 'jpg');
// => /images/profile.jpg

Path::join('phar://C:/Documents', 'projects/my-project.phar', 'composer.json');
// => phar://C:/Documents/projects/my-project.phar/composer.json

Path::getHomeDirectory();
// => /home/webmozart
```

Running tests
-------------

[](#running-tests)

- Clone the repository
- Install the dependencies with `composer install`
- Run the tests with `composer test`

Special Thanks
--------------

[](#special-thanks)

Special thanks goes to the folks at [LABOR.digital](https://labor.digital/) (which is the word german for laboratory and not the english "work" :D) for making it possible to publish my code online.

Postcardware
------------

[](#postcardware)

You're free to use this package, but if it makes it to your production environment I highly appreciate you sending me a postcard from your hometown, mentioning which of our package(s) you are using.

You can find my address [here](https://www.neunerlei.eu/).

Thank you :D

###  Health Score

48

—

FairBetter than 94% of packages

Maintenance88

Actively maintained with recent releases

Popularity16

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity64

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 ~180 days

Recently: every ~279 days

Total

13

Last Release

99d ago

Major Versions

5.5.1 → 6.0.02025-02-23

### Community

Maintainers

![](https://www.gravatar.com/avatar/0eb1c26fb5a535cd7a656faffbae7929009558b2bfa6156b2be7b636d689e13a?d=identicon)[labor-digital](/maintainers/labor-digital)

![](https://www.gravatar.com/avatar/c0356afb258572c8908df3132ea59545b7642a6b77fd90bc54215e506c42bfb7?d=identicon)[neunerlei](/maintainers/neunerlei)

---

Top Contributors

[![Neunerlei](https://avatars.githubusercontent.com/u/22350956?v=4)](https://github.com/Neunerlei "Neunerlei (20 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.3k511.3M2.2k](/packages/aws-aws-sdk-php)[terminal42/contao-fineuploader

FineUploader bundle for Contao Open Source CMS

2052.9k4](/packages/terminal42-contao-fineuploader)

PHPackages © 2026

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