code: def tree(path, pattern=None, dictionary=False):
      """Return a directory tree under the form of a dictionary or list.
  
      Parameters
      ----------
      path : string
          Path browsed.
  
      pattern : string, optional
          Pattern used to filter files (see fnmatch).
  
      dictionary : boolean, default=False
          If True, the function will return a dict instead of a list.
  
      """
      files = []
      dirs = {} if dictionary else []
      for file_ in os.listdir(path):
          file_path = os.path.join(path, file_)
          if os.path.isdir(file_path):
              if dictionary:
                  dirs[file_] = tree(file_path, pattern)
              else:
                  dirs.append((file_, tree(file_path, pattern)))
          elif pattern is None or fnmatch.fnmatch(file_, pattern):
              files.append(file_path)
      files = sorted(files)
      if not dictionary:
          return sorted(dirs) + files
      if len(dirs) == 0:
          return files
      if len(files) > 0:
          dirs["."] = files
      return dirs
  
imports: import collections.abc
  import contextlib
  import fnmatch
  import hashlib
  import os
  import pickle
  import shutil
  import sys
  import tarfile
  import time
  import urllib
  import warnings
  import zipfile
  from pathlib import Path
  import numpy
  import requests
  from .._utils import fill_doc
  from .utils import get_data_dirs
label_desc: Use image node_id 19 for calling a global function with example usage: tree(path, pattern, dictionary) and returns: dirs, unknown, files