def move_directory(path):
  """ Move existing directory to a new location (with a numbering scheme).
  Args:
    path Path to the directory to create
  Returns:
    'path' (to enable chaining)
  """
  # Move directory if it exists
  if path.exists():
    if not path.is_dir():
      raise RuntimeError(f"Expected to find nothing or (a symlink to) a directory at {str(path)!r}")
    i = 0
    while True:
      mvpath = path.parent / f"{path.name}.{i}"
      if not mvpath.exists():
        path.rename(mvpath)
        break
      i += 1
  # Enable chaining
  return path