Skip to main content

Overview

The FileScanner class is responsible for discovering source code files in a directory while respecting ignore rules and exclusions.

Constructor

Parameters:
  • rootDir (string): The root directory to scan
Example:

Properties

rootDir

The resolved absolute path of the root directory. Type: string

supportedExtensions

Set of supported file extensions. Type: Set<string> Default values:

ignoreDirs

Set of directory names to ignore during scanning. Type: Set<string> Default values:

gitignorePatterns

Array of patterns loaded from .gitignore. Type: string[]

Methods

scanFiles()

Scans the directory and returns an array of file paths.
Returns: Array of absolute file paths Example:
Output:

Private Methods

_loadGitignore()

Loads and parses the .gitignore file.
Returns: Array of gitignore patterns Implementation details:
  • Reads .gitignore from root directory
  • Filters out comments (lines starting with #)
  • Filters out empty lines
  • Returns array of patterns

_shouldIgnorePath(filePath)

Determines if a path should be ignored.
Parameters:
  • filePath (string): Path to check
Returns: true if should be ignored, false otherwise Checks:
  1. Built-in ignore directories
  2. Gitignore patterns

_scanDirectory(dir)

Recursively scans a directory.
Parameters:
  • dir (string): Directory to scan
Returns: Array of file paths

Usage Examples

Basic Scanning

Custom Extensions

Custom Ignore Directories

Filtering Results

Scan Multiple Directories

Count Files by Extension

Integration Examples

With AnalysisEngine

Selective Scanning

Progress Tracking

Gitignore Support

The FileScanner automatically respects .gitignore patterns:
These patterns are automatically applied:

Error Handling

FileScanner silently ignores inaccessible directories and continues scanning. This prevents permission errors from stopping the entire scan.

Performance Considerations

For very large codebases (> 10,000 files):
Add commonly large directories to ignoreDirs:
Remove unused extensions to reduce file count:

API Summary

Next Steps

AnalysisEngine

Learn how to analyze files

PatternScanner

Explore pattern detection

Usage Guide

See practical usage examples

Supported Languages

Check supported file types