code: def ls(root=".", abspaths=False, recursive=False):
      def _expand_subdirs(file):
          if isdir(path(root, file)):
              return [file] + [path(file, x) for x in
                               ls(path(root, file), recursive=True)]
          else:
              return [file]
      if isfile(root):
          return [abspath(root)] if abspaths else [basename(root)]
      elif abspaths:
          relpaths = ls(root, recursive=recursive, abspaths=False)
          base = abspath(root)
          return [path(base, relpath) for relpath in relpaths]
      elif recursive:
          paths = ls(root, abspaths=abspaths, recursive=False)
          return labtypes.flatten([_expand_subdirs(file) for file in paths])
      else:
          return list(sorted(os.listdir(root)))