file_system_globbing library
Provides support for matching file system paths using glob patterns with include/exclude semantics.
A port of Microsoft.Extensions.FileSystemGlobbing, supporting wildcards and directory recursion for flexible file selection.
Basic Glob Matching
Build a matcher and execute it against a directory:
final matcher = Matcher()
..addInclude('*.dart'); // Match all Dart files in current directory
Includes and excludes compose:
final matcher = Matcher()
// Include all Dart files
..addInclude('**/*.dart')
// Exclude generated files
..addExclude('**/*.g.dart')
..addExclude('**/*.freezed.dart')
// Exclude test files
..addExclude('**/test/**')
// Exclude build artifacts
..addExclude('**/build/**');
final projectDir = Directory.current.path;
final fullPaths = matcher.getResultsInFullPath(projectDir);
Pattern Syntax
Supported glob pattern features:
- exact names:
one.txt,dir/two.txt *- matches zero or more characters within a file or directory name, e.g.*.txt,readme.*,styles/*.css**- matches an arbitrary number of directory levels, e.g.**/*.cs,dir/**/*..- at the beginning of a pattern, refers to the parent directory- a trailing
/treats the pattern as a directory, e.g.lib/is equivalent tolib/**
In-Memory Matching
Test glob patterns against file paths without touching the disk:
final matcher = Matcher()..addInclude('*.dart');
final result = matcher.matchFiles(
['file1.dart', 'file2.txt'],
'/root',
);
Classes
- DirectoryInfoBase
- Enumerates all files and directories in the directory.
- DirectoryInfoWrapper
- FileInfoBase
- Represents a file
- FileInfoWrapper
- FilePatternMatch
- Represents a file that was matched by searching using a globbing pattern
- FileSystemInfoBase
- Shared abstraction for files and directories
- InMemoryDirectoryInfo
- Represents an in-memory directory for pattern matching without accessing the file system.
- InMemoryFileInfo
- Represents an in-memory file for pattern matching.
- Matcher
- Searches the file system for files with names that match specified patterns.
- PatternMatchingResult
- Represents a collection of FilePatternMatch
Enums
- StringComparison
- Specifies how two strings are compared during pattern matching.
Extensions
- MatcherExtensions on Matcher
- Extension methods for Matcher to simplify common operations.
Functions
-
stringComparisonKey(
String value, StringComparison comparisonType) → String -
Returns a canonical key for
valueundercomparisonType, suitable for direct==comparison or use in hash-based collections.