import stat


def filetype(mode):
  """
  Returns "dir" or "file" according to what type path is.

  @param mode: file mode from "stat" command.
  """
  if stat.S_ISLNK(mode):
    return "link"
  elif stat.S_ISDIR(mode):
    return "dir"
  elif stat.S_ISREG(mode):
    return "file"
  else:
    return "unknown"