IFileSystem Interface

Provides an abstraction for file system operations, enabling testability and custom file access implementations.

public interface IFileSystem

Methods

NameDescription
GetFiles(string, string, SearchOption)Gets the files in a directory matching the specified pattern.
OpenRead(string)Opens a file for reading.
OpenReadWrite(string)Opens a file for reading and writing.

GetFiles(string, string, SearchOption)

Gets the files in a directory matching the specified pattern.

IEnumerable<string> GetFiles(string path, string pattern, SearchOption searchOptions)

Parameters

path string
The directory path to search.
pattern string
The search pattern to match file names.
searchOptions SearchOption
Options controlling the search behavior.

Returns

IEnumerable<string> An enumerable collection of file paths.

Remarks

A directory scan with a custom file system calls this method with the * pattern to list the files to scan, and SearchOption.AllDirectories when ScannerOptions.RecurseSubdirectories is set. It should throw a DirectoryNotFoundException when the directory does not exist, which the scan then reports.

OpenRead(string)

Opens a file for reading.

Stream OpenRead(string path)

Parameters

path string
The path to the file to open.

Returns

Stream A stream for reading the file.

Remarks

The stream does not have to be seekable: a stream that is not is read into memory before the file is scanned.

OpenReadWrite(string)

Opens a file for reading and writing.

Stream OpenReadWrite(string path)

Parameters

path string
The path to the file to open.

Returns

Stream A stream for reading and writing the file.

Remarks

The stream must be seekable and support Stream.SetLength, because an update reads the whole file, then rewrites it from its start and truncates it to the new length.