import 'dart:io'; /// Total byte size of all files below [dir]; `0` when it doesn't exist or /// can't be listed. Future directorySize(Directory dir) async { var sum = 0; try { if (!dir.existsSync()) return 0; await for (final entity in dir.list(recursive: true, followLinks: false)) { if (entity is File) sum += await entity.length(); } } on FileSystemException { // Files can vanish mid-walk (cache pruning); report what was counted. } return sum; }