deleteChildren method

Future<bool> deleteChildren(
  1. String path, {
  2. required bool dryRun,
})

Implementation

Future<bool> deleteChildren(String path, {required bool dryRun}) async {
  if (isProtectedPath(path) || !Directory(path).existsSync()) return false;
  if (dryRun) return true;

  List<FileSystemEntity> children;
  try {
    children = await Directory(path).list(followLinks: false).toList();
  } on FileSystemException {
    return false;
  }

  var allDeleted = true;
  for (final child in children) {
    final deleted = await delete(child.path, dryRun: false);
    if (!deleted && exists(child.path)) {
      allDeleted = false;
    }
  }
  return allDeleted;
}