private static function doDirectoryOptions($basename, $filenames, $options) {
    $name_list = [];
    $results = [];
    // We need to know the path to the file so we can check if it's a directory.
    foreach($filenames as $file) {
      $name_list[] = ['name' => $file,
                      'path' => implode(DIRECTORY_SEPARATOR, [
                                        rtrim($basename, DIRECTORY_SEPARATOR),
                                        ltrim($file, DIRECTORY_SEPARATOR)]),
      ];
    }
    foreach($name_list as $name_and_path) {
      $name = $name_and_path['name'];
      $isdir = is_dir($name_and_path['path']);
      if (($options & GLOB_MARK) && $isdir) {
        $name = rtrim($name, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
      }
      if ($options & GLOB_ONLYDIR) {
        if ($isdir) {
          $results[] = $name;
        }
      } else {
        $results[] = $name;
      }
    }
    return $results;
  }