removeEntry method

Future<void> removeEntry(
  1. String name, {
  2. bool recursive = false,
})

Attempts to asynchronously remove an entry if the directory handle contains a file or directory called the name specified.

recursive: when set to true entries will be removed recursively, default false.

Throws a NotAllowedError if the state for the handle is not PermissionState.granted. Throws a MalformedNameError if the name is not a valid string or contains characters not allowed on the file system. Throws an InvalidModificationError if recursive is set to false and the entry to be removed has children. Throws a NotFoundError if an entry name is not found or matched, or this requested directory could not be found at the time operation was processed.

Implementation

Future<void> removeEntry(String name, {bool recursive = false}) {
  try {
    final options = [name, FileSystemRemoveOptions(recursive: recursive)];

    return promiseToFuture(callMethod(this, "removeEntry", options));
  } catch (error) {
    if (jsIsNativeError(error, "NotAllowedError")) {
      throw NotAllowedError();
    } else if (jsIsNativeError(error, "TypeError")) {
      throw MalformedNameError();
    } else if (jsIsNativeError(error, "InvalidModificationError")) {
      throw InvalidModificationError();
    } else if (jsIsNativeError(error, "NotFoundError")) {
      throw NotFoundError();
    } else {
      rethrow;
    }
  }
}