Recursively scans a directory and loads every file whose extension has a registered loader in the supplied LoaderRegistry.

Example

const registry = new LoaderRegistry();
const scanner = new FolderScanner(registry);

const result = await scanner.scan('/knowledge-base', {
recursive: true,
include: ['**/*.md', '**/*.pdf'],
exclude: ['**/node_modules/**'],
onProgress: (file, i, total) => console.log(`${i}/${total} ${file}`),
});

console.log(`Loaded ${result.documents.length} documents`);
console.log(`Failed: ${result.failed.length}`);

Constructors

Methods

Constructors

Methods

  • Walk dirPath and load every matching file.

    Files are discovered first and then loaded sequentially. Errors thrown by individual loaders are caught and accumulated in the returned failed list rather than propagating.

    Parameters

    • dirPath: string

      Absolute path to the directory to scan.

    • options: FolderScanOptions = {}

      Optional include/exclude filters and progress callback.

    Returns Promise<FolderScanResult>

    A promise that resolves to a FolderScanResult.

    Throws

    When dirPath cannot be read as a directory (e.g. it does not exist or is a regular file).