Laravel File Storage delete all files in directory

ßiansor Å. Ålmerol picture ßiansor Å. Ålmerol · Oct 30, 2017 · Viewed 27.6k times · Source

Is there a way to delete all files in specific directory. I'm trying to clear all my files in my created folder backgrounds in storage\app\backgrounds but in docs seems no method for delete all.

Storage::delete('backgrounds\*.jpg');

Answer

ßiansor Å. Ålmerol picture ßiansor Å. Ålmerol · Oct 30, 2017

I don't think if this is the best way to solve this. But I solved mine calling

use Illuminate\Filesystem\Filesystem;

Then initiate new instance

$file = new Filesystem;
$file->cleanDirectory('storage/app/backgrounds');