code: public function isEmpty($filter = null): bool
      {
          if (! $this->exists()) {
              throw new DirectoryException("Directory {dir} does not exist", array(
                  'dir' => $this->path
              ));
          }
          
          $iter = new \DirectoryIterator($this->path);
          while ($iter->valid()) {
              if (! $iter->isDot() && ($filter === null || ! preg_match("/$filter/", $iter->getFilename()))) {
                  return false;
              }
              $iter->next();
          }
          
          return true;
      }
docs: Checks whether directory is empty or not
  
  @param string $filter
  The filter for entries to skip
  
  @return bool
  
  @throws DirectoryException