Symfony\Component\Finder\Finder::directories PHP Method

directories() public method

Restricts the matching to directories only.
public directories ( ) : Finder | Symfony\Component\Finder\SplFileInfo[]
return Finder | Symfony\Component\Finder\SplFileInfo[] The current Finder instance
    public function directories()
    {
        $this->mode = Iterator\FileTypeFilterIterator::ONLY_DIRECTORIES;

        return $this;
    }

Usage Example

Example #1
0
 /**
  * fire.
  */
 public function fire()
 {
     // set_time_limit(30);
     $path = $this->argument('path');
     $name = $this->option('name');
     $type = $this->option('type');
     $maxDepth = $this->option('maxdepth');
     $delete = $this->option('delete');
     $root = $this->getLaravel()->basePath();
     $path = realpath($root . '/' . $path);
     $this->finder->in($path);
     if ($name !== null) {
         $this->finder->name($name);
     }
     switch ($type) {
         case 'd':
             $this->finder->directories();
             break;
         case 'f':
             $this->finder->files();
             break;
     }
     if ($maxDepth !== null) {
         if ($maxDepth == '0') {
             $this->line($path);
             return;
         }
         $this->finder->depth('<' . $maxDepth);
     }
     foreach ($this->finder as $file) {
         $realPath = $file->getRealpath();
         if ($delete === 'true' && $filesystem->exists($realPath) === true) {
             try {
                 if ($filesystem->isDirectory($realPath) === true) {
                     $deleted = $filesystem->deleteDirectory($realPath, true);
                 } else {
                     $deleted = $filesystem->delete($realPath);
                 }
             } catch (Exception $e) {
             }
             if ($deleted === true) {
                 $this->info('removed ' . $realPath);
             } else {
                 $this->error('removed ' . $realPath . ' fail');
             }
         } else {
             $this->line($file->getRealpath());
         }
     }
 }
All Usage Examples Of Symfony\Component\Finder\Finder::directories