rename static method

FutureResult<(), IoError> rename(
  1. Path path,
  2. String newName
)

Renames a file or directory. Note this is different from the rust rename as this is just a rename, for an equivalent use - move.

Implementation

static FutureResult<(), IoError> rename(Path path, String newName) async {
  final pathStr = path.asString();
  final lastSeparatorIndex = pathStr.lastIndexOf(Path.separator);
  final newPath = pathStr.substring(0, lastSeparatorIndex + 1) + newName;
  return Fs.move(path, newPath.asPath());
}