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

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

ralphjsmit/filesystem
=====================

A fluent filesystem package for PHP.

1.4.0(3y ago)181.9k3[2 PRs](https://github.com/ralphjsmit/filesystem/pulls)1MITPHPPHP ^8.0

Since Dec 31Pushed 2y ago3 watchersCompare

[ Source](https://github.com/ralphjsmit/filesystem)[ Packagist](https://packagist.org/packages/ralphjsmit/filesystem)[ Docs](https://github.com/ralphjsmit/filesystem)[ RSS](/packages/ralphjsmit-filesystem/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (5)Dependencies (11)Versions (9)Used By (1)

[![Stubs Banner](https://github.com/ralphjsmit/filesystem/raw/main/docs/images/filesystem.jpg)](https://github.com/ralphjsmit/filesystem/blob/main/docs/images/filesystem.jpg)

A fluent filesystem package for PHP
===================================

[](#a-fluent-filesystem-package-for-php)

This package helps you to speed up the process of moving and copying files. It also makes replacing namespaces much easier, thus making it an invaluable tool for heavy filesystem tasks. Enjoy!

Important

This package is only updated until Laravel 10.

[⚡️ See the release article on my website or subscribe to my newsletter for an occasional update](https://ralphjsmit.com/php-fluent-filesystem-package/)

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

[](#installation)

You can install the package via composer:

```
composer require ralphjsmit/filesystem
```

Usage
-----

[](#usage)

This package works by providing you with a base `Stub` class and a `File` class. As the name implies, the `Stub` class is an object that contains specific configuration, like the namespaces and the base directory. The `File` class is used to represent an individual file.

### Creating a Stub configuration

[](#creating-a-stub-configuration)

You can create a new `Stub` configuration with `Stub::new()`:

```
use RalphJSmit\Filesystem\Stub;

$stub = Stub::new();
```

You can use a `Stub` configuration like this (I'll talk more about file actions below):

```
$stub->getFile(__DIR__ . '/tmp/testFileA.php')->move(__DIR__ . '/tmp/otherFolder');
```

You can also set a base directory for your `Stub`:

```
$stub = Stub::dir(__DIR__);

$stub->getFile('/tmp/testFileA.php')->move('/tmp/otherFolder');
```

If you already have a `$stub` instance, you can configure namespaces on them. Those namespaces are used on the `File` object for the `->namespace()` action. It basically means that you define the directories for each namespace in your project.

```
$stubs = Stub::dir(__DIR__)->namespaces([
    'Support' => '/src/Support/',
    'Domain' => '/src/Domain/',
    'App' => '/src/App/',
]);

$stubs->getFile('/tmp/TestFileA.php')->namespace('Support/Models');
// Moves __DIR__ . `/tmp/testFileA.php` to __DIR__ . `/src/Support/Models/testFileA.php`.
```

You can also have multiple stub configurations at the same time:

```
$stubA = Stub::dir(__DIR__ . '/src');
$stubB = Stub::dir(__DIR__ . '/app');
$stubC = Stub::dir(__DIR__ . '/tmp');
```

Getting a File object
---------------------

[](#getting-a-file-object)

You can get a `File` object by directly calling `file()` on the `Stub` class:

```
$file = Stub::file(__DIR__ . '/tmp/testFileA.php');
```

You can also get a `File` object from a `$stub` instance:

```
$stub = Stub::dir(__DIR__);

$file = $stub->getFile('/tmp/testFileA.php');
```

### Actions on a File object

[](#actions-on-a-file-object)

If you have a `File` object, you can perform the following actions on it:

#### Copying a file

[](#copying-a-file)

You can copy a file to a new **directory** using the `copy()` function:

```
$file = Stub::dir(__DIR__)->getFile('/tmp/testFileA.php')->copy('/tmp/test');
// $file is now in __DIR__ . '/tmp/testFileA.php' AND in __DIR__ . '/tmp/test/testFileA.php'
```

#### Deleting a file

[](#deleting-a-file)

You can delete a file using the `delete()` function:

```
Stub::dir(__DIR__)->getFile('/tmp/testFileA.php')->delete();
// returns true on success
```

#### Getting the basename of a file

[](#getting-the-basename-of-a-file)

You can get the basename of a file using the `getBasename()` function:

```
Stub::dir(__DIR__)->getFile('/tmp/testFileA.php')->getBasename();
// 'testFileA.php'
```

#### Getting the directory location of a file

[](#getting-the-directory-location-of-a-file)

You can get the location of the directory of a file using the `getDirectory()` function:

```
Stub::dir(__DIR__)->getFile('/tmp/testFileA.php')->getDirectory();
// __DIR__ . '/tmp'
```

#### Getting the full path of a file

[](#getting-the-full-path-of-a-file)

You can get the full path of a file using the `getFilepath()` function:

```
Stub::dir(__DIR__)->getFile('/tmp/testFileA.php')->getFilepath();
// __DIR__ . '/testFileA.php'
```

#### Getting the file contents

[](#getting-the-file-contents)

You can get the contents of a file using the `getContents()` function:

```
$contents = Stub::dir(__DIR__)->getFile('/tmp/testFileA.php')->getContents();
```

#### Moving a file

[](#moving-a-file)

You can move a file to a new **directory** using the `move()` function:

```
$file = Stub::dir(__DIR__)->getFile('/tmp/testFileA.php')->move('/tmp/test');
// $file is now in __DIR__ . '/tmp/test/testFileA.php'
```

#### Updating the namespace of a file

[](#updating-the-namespace-of-a-file)

You may update the namespace of a file and move it to the correct directory with the `namespace()` helper. This is ideal if you need to move a PHP-file to a new directory *and* update its namespace. I use this technique in the [ralphjsmit/tall-install](https://github.com/ralphjsmit/tall-install/) package.

```
$basePath = __DIR__;

$stubs = Stub::dir($basePath)->namespaces([
    'Support' => '/src/Support/',
    'Domain' => '/src/Domain/',
    'App' => '/src/App/',
]);

$stubs->getFile('/app/Console/Kernel.php')->namespace('Support\App\Console');
// file is not in __DIR__ . '/src/Support/App/Console/Kernel.php'
```

[Checkout a real-life example from one of my packages](https://github.com/ralphjsmit/tall-install/blob/main/src/Actions/DDD/UpdateFileStructureAction.php).

#### Updating the contents of a file

[](#updating-the-contents-of-a-file)

You may update the contents of a file with the `putFile()` method:

```
$newContents = 'Hello world!';

$file = Stub::dir(__DIR__)->getFile('/tmp/testFileA.php')->putFile($newContents);
```

You may also specify a new location for the file:

```
$newContents = 'Hello world!';

$file = Stub::dir(__DIR__)->getFile('/tmp/testFileA.php')->putFile($newContents, '/tmp/test/myFile.php');
// Will create a file with the "Hello world!" in __DIR__ . '/tmp/test/myFile.php`
// Old file will still exist
```

If you just want to move or copy a file, you should use those methods.

#### Updating the namespace of a file

[](#updating-the-namespace-of-a-file-1)

You may replace the namespace of a file with the `replaceNamespace($newNamespace)` method:

```
$file = Stub::dir(__DIR)->getFile('/tmp/test/MyClass.php');

$file->replaceNamespace('App\Models');

// $file will now have the namespace App\Models
```

General
-------

[](#general)

🐞 If you spot a bug, please submit a detailed issue, and I'll try to fix it as soon as possible.

🔐 If you discover a vulnerability, please review [our security policy](../../security/policy).

🙌 If you want to contribute, please submit a pull request. All PRs will be fully credited. If you're unsure whether I'd accept your idea, feel free to contact me!

🙋‍♂️ [Ralph J. Smit](https://ralphjsmit.com)

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 77.4% 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 ~103 days

Total

5

Last Release

1221d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/59207045?v=4)[Ralph J. Smit](/maintainers/ralphjsmit)[@ralphjsmit](https://github.com/ralphjsmit)

---

Top Contributors

[![ralphjsmit](https://avatars.githubusercontent.com/u/59207045?v=4)](https://github.com/ralphjsmit "ralphjsmit (89 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (13 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (12 commits)")[![alexmartinfr](https://avatars.githubusercontent.com/u/19224681?v=4)](https://github.com/alexmartinfr "alexmartinfr (1 commits)")

---

Tags

phpfilesystemlaravelralphjsmit

###  Code Quality

TestsPest

### Embed Badge

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

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

###  Alternatives

[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.3M42](/packages/spatie-laravel-pdf)[illuminate/filesystem

The Illuminate Filesystem package.

15263.8M3.0k](/packages/illuminate-filesystem)[spatie/laravel-health

Monitor the health of a Laravel application

87411.3M152](/packages/spatie-laravel-health)[nativephp/desktop

NativePHP for Desktop

38133.6k8](/packages/nativephp-desktop)[elegantly/laravel-translator

All on one translations management for Laravel

6326.3k](/packages/elegantly-laravel-translator)[lunarstorm/laravel-ddd

A Laravel toolkit for Domain Driven Design patterns

18476.4k](/packages/lunarstorm-laravel-ddd)

PHPackages © 2026

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