This package allows you to simply work with directories. Create, delete, rename and empty directories.
You can install the package via composer:
composer require grinderspro/directory-manipulator
To create a directory, use the create()
method. If you use the create()
method without parameters, then the directory will be created in the temporary system folder by default.
require __DIR__ . '/vendor/autoload.php';
use Grinderspro\DirectoryManipulator\DirectoryManipulator;
(new DirectoryManipulator())->create();
Create many directories
$dm = (new DirectoryManipulator())->location('/var/tmp/')->clear();
for ($i=1; $i<=10; ++$i) {
$dm->name('gm'.$i)->create();
}
Create directory - "/var/tmp/{time()}"
(new DirectoryManipulator())->location('/var/tmp/')->name()->create();
Create directory - "/var/tmp/grinderspro"
(new DirectoryManipulator())->location('/var/tmp/')->name('grinderspro')->create();
(new DirectoryManipulator())->location('/var/tmp/grinderspro')->create();
if((new DirectoryManipulator())->location('/var/tmp/grinderspro')->create())
return true;
To get the full path of the newly created directory, use the path()
method without parameters.
$dirName = (new DirectoryManipulator())->create('/var/tmp/')->name()->path();
(new DirectoryManipulator())->location('/var/tmp/')->name('grinderspro')->delete();
(new DirectoryManipulator())->location('/var/tmp/grinderspro')->delete();
(new DirectoryManipulator())->location('/var/tmp/grinderspro')->clear();