move static method

FutureResult<(), IoError> move(
  1. Path from,
  2. Path to
)

Moves a file or directory, possibly just a rename operation.

Implementation

static FutureResult<(), IoError> move(Path from, Path to) async {
  final fromStr = from.asString();
  final toStr = to.asString();
  return await Fs.ioGuardResult(() async {
    FileSystemEntity entity = File(fromStr);
    if (await entity.exists()) {
      return Ok(await entity.rename(toStr));
    }
    entity = Directory(fromStr);
    if (await entity.exists()) {
      return Ok(await entity.rename(toStr));
    }
    entity = Link(fromStr);
    if (await entity.exists()) {
      return Ok(await entity.rename(toStr));
    }
    return Err(
        IoError.ioException(PathNotFoundException(fromStr, const OSError())));
  }).map((_) => ());
}