deleteDirectory function

Future deleteDirectory(
  1. Directory dir, {
  2. DeleteOptions? options,
})

Delete a directory recursively

Implementation

Future deleteDirectory(Directory dir, {DeleteOptions? options}) async {
  options ??= defaultDeleteOptions;

  try {
    await dir.delete(recursive: options.recursive);
  } catch (e) {
    if (e is FileSystemException) {
      if (e.status != FileSystemException.statusNotFound) {
        if (!options.recursive &&
            e.status == FileSystemException.statusNotEmpty) {
          // ok
        } else {
          // ignore: avoid_print
          print('delete $dir failed $e');
        }
      }
    } else {
      // ignore: avoid_print
      print('delete $dir failed $e');
    }
  }
  if (options.create) {
    await dir.create(recursive: true);
  }
}