scanFolder method
Implementation
Future<ScanResult> scanFolder() async {
int fileCount = 0;
int bytes = 0;
int deleteCount = 0;
Directory folder = Directory(path);
if (folder.existsSync()) {
await for (FileSystemEntity e in folder.list(
recursive: true,
followLinks: false,
)) {
final stat = await e.stat();
if (stat.type == FileSystemEntityType.directory) continue;
fileCount += 1;
bytes += stat.size;
CacheEntry entry;
File file = File(e.path);
try {
entry = await CacheEntry.fromFile(
file,
loadContent: false,
);
} catch (error) {
await file.delete(recursive: false);
continue;
}
if (!entry.isValid()) {
await e.delete(recursive: false);
deleteCount += 1;
}
}
}
return ScanResult(
fileCount: fileCount,
bytes: bytes,
deleteCount: deleteCount,
);
}