deleteAll function

Future<void> deleteAll(
  1. FileCollection fileCollection
)

Delete all files and possibly directories included in the given fileCollection.

Directories are only deleted if after deleting all FileCollection.files, the directories end up being empty. In other words, directories are deleted as long as no filters belonging to the given FileCollection exclude files or sub-directories within such directory.

Implementation

Future<void> deleteAll(FileCollection fileCollection) async {
  final toDelete = await fileCollection.resolve().toList();
  // the list is in listed-files order, so we must reverse it to delete
  // directories last.
  for (final entry in toDelete.reversed) {
    logger.fine('Deleting ${entry.path}');
    final ok =
        await ignoreExceptions(() => entry.entity.delete(recursive: false));
    if (!ok) {
      logger.fine(() => 'Did not delete: ${entry.path}');
    }
  }
}