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):
          # If argument is a file, return path.
          return [abspath(root)] if abspaths else [basename(root)]
      elif abspaths:
          # Get relative names.
          relpaths = ls(root, recursive=recursive, abspaths=False)
          # Prepend the absolute path to each relative name.
          base = abspath(root)
          return [path(base, relpath) for relpath in relpaths]
      elif recursive:
          # Recursively expand subdirectories.
          paths = ls(root, abspaths=abspaths, recursive=False)
          return labtypes.flatten([_expand_subdirs(file) for file in paths])
      else:
          # List directory contents.
          return list(sorted(os.listdir(root)))
docs: Return a list of files in directory.
  
      Directory listings are sorted alphabetically. If the named
      directory is a file, return it's path.
  
      Examples:
  
          >>> fs.ls("foo")
          ["a", "b", "c"]
  
          >>> fs.ls("foo/a")
          ["foo/a"]
  
          >>> fs.ls("foo", abspaths=True)
          ["/home/test/foo/a", "/home/test/foo/b", "/home/test/foo/c"]
  
          >>> fs.ls("foo", recursive=True)
          ["a", "b", "b/d", "b/d/e", "c"]
  
      Arguments:
  
          root (str): Path to directory. Can be relative or absolute.
          abspaths (bool, optional): Return absolute paths if true.
          recursive (bool, optional): Recursively list subdirectories if
            true.
  
      Returns:
  
          list of str: A list of paths.
  
      Raises:
  
          OSError: If root directory does not exist.