PHPackages                             minh7721/laravel-directory-cleanup - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. minh7721/laravel-directory-cleanup

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

minh7721/laravel-directory-cleanup
==================================

This package will remove the expired files from the given directories.

1.10.0(2y ago)041MITPHPPHP ^8.0|^8.1

Since May 6Pushed 2y agoCompare

[ Source](https://github.com/minh7721/laravel-directory-cleanup)[ Packagist](https://packagist.org/packages/minh7721/laravel-directory-cleanup)[ Docs](https://github.com/spatie/laravel-directory-cleanup)[ Fund](https://spatie.be/open-source/support-us)[ RSS](/packages/minh7721-laravel-directory-cleanup/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

Delete old files in Laravel apps
================================

[](#delete-old-files-in-laravel-apps)

[![Latest Version on Packagist](https://camo.githubusercontent.com/c9f2ef7db8e23e1e467009261a679c8ebca0d57f7379f0b72ae1888578b24b45/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6c61726176656c2d6469726563746f72792d636c65616e75702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-directory-cleanup)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Test Status](https://camo.githubusercontent.com/7dc9fe64d04059a3bb2af224fc0c15ee3016fa74c832aaf29f12269d55bcd0db/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7370617469652f6c61726176656c2d6469726563746f72792d636c65616e75702f72756e2d74657374733f6c6162656c3d7465737473)](https://camo.githubusercontent.com/7dc9fe64d04059a3bb2af224fc0c15ee3016fa74c832aaf29f12269d55bcd0db/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7370617469652f6c61726176656c2d6469726563746f72792d636c65616e75702f72756e2d74657374733f6c6162656c3d7465737473)[![PHP CS Fixer Status](https://camo.githubusercontent.com/5804ed6415379cfdca2fd6ad2bf24b0e7d4100730428c4b472a5890b701f9e60/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7370617469652f6c61726176656c2d6469726563746f72792d636c65616e75702f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://camo.githubusercontent.com/5804ed6415379cfdca2fd6ad2bf24b0e7d4100730428c4b472a5890b701f9e60/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7370617469652f6c61726176656c2d6469726563746f72792d636c65616e75702f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)[![Total Downloads](https://camo.githubusercontent.com/c9694491e08a2ad85aabf17d26064bcf42f7cc64d1dfc8677744ced24e94939d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6c61726176656c2d6469726563746f72792d636c65616e75702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-directory-cleanup)

This package will delete old files from directories. You can use a configuration file to specify the maximum age of a file in a certain directory.

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/6fcca4a181540adfa8bb1a5ba4e7a0467244b1f520bbf4b0274c032af9d2af3b/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f6c61726176656c2d6469726563746f72792d636c65616e75702e6a70673f743d31)](https://spatie.be/github-ad-click/laravel-directory-cleanup)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

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

[](#installation)

You can install the package via composer:

```
composer require nguyenhiep/laravel-directory-cleanup
```

In Laravel 5.5 the service provider will automatically get registered. In older versions of the framework just add the service provider in `config/app.php` file:

```
'providers' => [
    ...
    Spatie\DirectoryCleanup\DirectoryCleanupServiceProvider::class,

];
```

Next, you must publish the config file:

```
php artisan vendor:publish --provider="Spatie\DirectoryCleanup\DirectoryCleanupServiceProvider"
```

This is the content of the published config file `laravel-directory-cleanup`

```
return [

    'directories' => [

        /*
         * Here you can specify which directories need to be cleanup. All files older than
         * the specified amount of minutes will be deleted.
         */

        /*
        'path/to/a/directory' => [
            'deleteAllOlderThanMinutes' => 60 * 24,
            'extensions' => "*" // "*"|"png,jpg"
        ],
        */
    ],

    /*
     * If a file is older than the amount of minutes specified, a cleanup policy will decide if that file
     * should be deleted. By default every file that is older than the specified amount of minutes
     * will be deleted.
     *
     * You can customize this behaviour by writing your own clean up policy.  A valid policy
     * is any class that implements `Spatie\DirectoryCleanup\Policies\CleanupPolicy`.
     */
    'cleanup_policy' => \Spatie\DirectoryCleanup\Policies\DeleteEverything::class,
];

```

Usage
-----

[](#usage)

Specify the directories that need cleaning in the config file.

When running the console command `clean:directories` all files in the specified directories older than `deleteAllOlderThanMinutes` will be deleted. Empty subdirectories will also be deleted.

This command can be scheduled in Laravel's console kernel.

```
// app/Console/Kernel.php

protected function schedule(Schedule $schedule)
{
   $schedule->command('clean:directories')->daily();
}
```

Writing a custom clean up policy
--------------------------------

[](#writing-a-custom-clean-up-policy)

If you want to apply additional conditional logic before a file is deleted, you can replace the default `cleanup_policy` with a custom one. Create a class which implements `Spatie\DirectoryCleanup\Policies\CleanupPolicy` and add your logic to the `shouldDelete` method.

```
// app/CleanupPolicies/MyPolicy.php

namespace App\CleanupPolicies;

use Symfony\Component\Finder\SplFileInfo;
use Spatie\DirectoryCleanup\Policies\CleanupPolicy;

class MyPolicy implements CleanupPolicy
{
    public function shouldDelete(SplFileInfo $file) : bool
    {
        $filesToKeep = ['robots.txt'];

        return ! in_array($file->getFilename(), $filesToKeep);
    }
}
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Jolita Grazyte](https://github.com/JolitaGrazyte)
- [Freek Van der Herten](https://github.com/freekmurze)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% 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

Unknown

Total

1

Last Release

737d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8f2cbed74179f4b5d8cfaac946240fbbc65bc8b081864e9bfd0ac0eed9be07ec?d=identicon)[minh7721](/maintainers/minh7721)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (40 commits)")[![nguyenhiepvan](https://avatars.githubusercontent.com/u/33170716?v=4)](https://github.com/nguyenhiepvan "nguyenhiepvan (12 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (6 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (4 commits)")[![mariavilaro](https://avatars.githubusercontent.com/u/10522884?v=4)](https://github.com/mariavilaro "mariavilaro (2 commits)")[![minh7721](https://avatars.githubusercontent.com/u/57635053?v=4)](https://github.com/minh7721 "minh7721 (2 commits)")[![gsi-luis](https://avatars.githubusercontent.com/u/44478194?v=4)](https://github.com/gsi-luis "gsi-luis (1 commits)")[![LasseRafn](https://avatars.githubusercontent.com/u/2689341?v=4)](https://github.com/LasseRafn "LasseRafn (1 commits)")[![m1guelpf](https://avatars.githubusercontent.com/u/23558090?v=4)](https://github.com/m1guelpf "m1guelpf (1 commits)")[![neochief](https://avatars.githubusercontent.com/u/121889?v=4)](https://github.com/neochief "neochief (1 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")[![poldixd](https://avatars.githubusercontent.com/u/695449?v=4)](https://github.com/poldixd "poldixd (1 commits)")[![Schnoop](https://avatars.githubusercontent.com/u/1263407?v=4)](https://github.com/Schnoop "Schnoop (1 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (1 commits)")[![stefanzweifel](https://avatars.githubusercontent.com/u/1080923?v=4)](https://github.com/stefanzweifel "stefanzweifel (1 commits)")[![akoepcke](https://avatars.githubusercontent.com/u/5311185?v=4)](https://github.com/akoepcke "akoepcke (1 commits)")[![alexbowers](https://avatars.githubusercontent.com/u/842974?v=4)](https://github.com/alexbowers "alexbowers (1 commits)")[![andreasnij](https://avatars.githubusercontent.com/u/1712334?v=4)](https://github.com/andreasnij "andreasnij (1 commits)")[![bluec](https://avatars.githubusercontent.com/u/1577895?v=4)](https://github.com/bluec "bluec (1 commits)")[![chapeupreto](https://avatars.githubusercontent.com/u/834048?v=4)](https://github.com/chapeupreto "chapeupreto (1 commits)")

---

Tags

spatielaravel-directory-cleanup

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/minh7721-laravel-directory-cleanup/health.svg)

```
[![Health](https://phpackages.com/badges/minh7721-laravel-directory-cleanup/health.svg)](https://phpackages.com/packages/minh7721-laravel-directory-cleanup)
```

###  Alternatives

[spatie/laravel-directory-cleanup

This package will remove the expired files from the given directories.

3061.4M6](/packages/spatie-laravel-directory-cleanup)[spatie/laravel-schedule-monitor

Monitor scheduled tasks in a Laravel app

9815.7M9](/packages/spatie-laravel-schedule-monitor)[spatie/laravel-google-calendar

Manage events on a Google Calendar

1.4k1.5M21](/packages/spatie-laravel-google-calendar)[spatie/laravel-enum

Laravel Enum support

3655.4M31](/packages/spatie-laravel-enum)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[spatie/laravel-personal-data-export

Create personal data downloads in a Laravel app

550543.8k8](/packages/spatie-laravel-personal-data-export)

PHPackages © 2026

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