findFiles static method

Stream<File> findFiles(
  1. {String? subPath,
  2. String? rootDir,
  3. RegExp? matcher}
)

An async Stream of File instances found responsive to the matcher within the rootDir/subPath location on the file system. THe rootDir will default to Directory.current if not provided

Implementation

static Stream<File> findFiles({
  String? subPath,
  String? rootDir,
  RegExp? matcher,
}) async* {
  final finalRoot = rootDir ?? Directory.current.path;
  final finalSub = subPath ?? '';
  final finalPath = path.join(finalRoot, finalSub);
  final baseDir = Directory(finalPath);
  if (baseDir.existsSync()) {
    await for (var entry in baseDir.list(recursive: true)) {
      if (entry is File &&
          (matcher == null || matcher.hasMatch(entry.path))) {
        yield entry;
      }
    }
  }
}