use Illuminate\Filesystem\Filesystem; $fileSystem = new Filesystem(); // Check if a file exists if ($fileSystem->exists('/path/to/file.txt')) { // Delete the file $fileSystem->delete('/path/to/file.txt'); } // Read a file $fileContents = $fileSystem->get('/path/to/file.txt'); // Write to a file $fileSystem->put('/path/to/file.txt', 'This is a test'); // Move a file $fileSystem->move('/path/to/old-file.txt', '/path/to/new-file.txt');
use Illuminate\Filesystem\Filesystem; $fileSystem = new Filesystem(); // Use the files method to get a list of all files in the directory $files = $fileSystem->files('/path/to/directory'); // Use the allFiles method to get a list of all files and subdirectories in the directory $allFiles = $fileSystem->allFiles('/path/to/directory'); // Use the directories method to get a list of all directories in the directory $dirs = $fileSystem->directories('/path/to/directory'); // Filter files by extension $files = $fileSystem->files('/path/to/directory'); $filtered = $files->filter(function ($file) { return ends_with($file, '.txt'); });Laravel framework is the package library used in the above examples.