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;
  }

  for (final child in children) {
    await delete(child.path, dryRun: false);
  }
  return true;
}