delCopies method

Future delCopies({
  1. required String name,
  2. String spaces = lazy.defaultGDriveSpace,
  3. int keepNumberOfLatest = 5,
})

Delete old copies of file with name in spaces and keep number of latest copy.

  • name is filename
  • spaces Google Drive Space. default to 'appDataFolder'
  • keepNumberOfLatest copy to be kept

Implementation

Future delCopies({
  required String name,
  String spaces = lazy.defaultGDriveSpace,
  int keepNumberOfLatest = 5,
}) async {
  var debugPrefix = '$runtimeType.cleanUpOldFiles()';
  List<gd.File> gFiles = await listFiles(
    name: name,
    spaces: spaces,
  );
  if (gFiles.length > keepNumberOfLatest) {
    for (var gFile in gFiles.sublist(0, gFiles.length - keepNumberOfLatest)) {
      if (gFile.id != null) {
        lazy.log('$debugPrefix: deleted ${gFile.name} id: ${gFile.id}');
        del(gFile.id!);
      }
    }
  }
}