use Symfony\Component\Filesystem\Filesystem; $filesystem = new Filesystem(); // clean all .log files $filesystem->remove(glob('/path/to/directory/*.log')); // clean all .tmp files $filesystem->remove(glob('/path/to/directory/*.tmp')); // clean all .bak files $filesystem->remove(glob('/path/to/directory/*.bak'));
use Symfony\Component\Filesystem\Filesystem; $filesystem = new Filesystem(); // get all empty directories $emptyDirectories = array_filter(glob('/path/to/directory/*'), 'is_dir'); foreach ($emptyDirectories as $dir) { if (!glob($dir . '/*')) { // check if directory is empty $filesystem->remove($dir); // remove the empty directory } }Package Library: Symfony Filesystem Component