scan method

Future<void> scan(
  1. List<String> directories, {
  2. bool recursive = true,
})

Implementation

Future<void> scan(List<String> directories, {bool recursive = true}) async {
  if (kIsWeb || _scanning) return;
  _scanning = true;
  _scanned = 0;
  _scanTotal = 0;
  notifyListeners();
  try {
    final List<File> found = <File>[];
    for (final String path in directories) {
      final Directory directory = Directory(path);
      if (!directory.existsSync()) continue;
      await for (final FileSystemEntity entity in directory.list(recursive: recursive, followLinks: false)) {
        if (entity is! File) continue;
        final String lower = entity.path.toLowerCase();
        if (extensions.any(lower.endsWith)) found.add(entity);
      }
    }
    _scanTotal = found.length;
    notifyListeners();
    for (final File file in found) {
      await _ingest(file);
      _scanned++;
      if (_scanned % 16 == 0) notifyListeners();
    }
    await save();
  } on Object {
    return;
  } finally {
    _scanning = false;
    notifyListeners();
  }
}