Interface IFileSystem
- Namespace
- ProjGraph.Lib.Core.Abstractions
- Assembly
- ProjGraph.Lib.Core.dll
Provides an abstraction for file system operations to improve testability.
public interface IFileSystem
Methods
Combine(params string[])
Combines multiple path strings into a single path.
string Combine(params string[] paths)
Parameters
pathsstring[]An array of parts of the path to combine.
Returns
- string
The combined path.
CreateDirectory(string)
Creates all directories in the specified path unless they already exist.
void CreateDirectory(string path)
Parameters
pathstringThe directory path to create.
DirectoryExists(string)
Checks if a directory exists at the specified path.
bool DirectoryExists(string path)
Parameters
pathstringThe path to the directory.
Returns
- bool
True if the directory exists, otherwise false.
EnumerateDirectories(string, string, EnumerationOptions)
Returns an enumerable collection of directory full names that match a search pattern in a specified path, using the specified enumeration options.
IEnumerable<string> EnumerateDirectories(string path, string searchPattern, EnumerationOptions options)
Parameters
pathstringThe directory path.
searchPatternstringThe search string to match against the names of directories.
optionsEnumerationOptionsThe enumeration options to use.
Returns
- IEnumerable<string>
An enumerable collection of the full names of directories that match the search pattern.
EnumerateFiles(string, string, EnumerationOptions)
Returns an enumerable collection of full file names that match a search pattern in a specified path, using the specified enumeration options.
IEnumerable<string> EnumerateFiles(string path, string searchPattern, EnumerationOptions options)
Parameters
pathstringThe directory path.
searchPatternstringThe search string to match against the names of files.
optionsEnumerationOptionsThe enumeration options to use.
Returns
- IEnumerable<string>
An enumerable collection of the full names of files that match the search pattern.
FileExists(string)
Checks if a file exists at the specified path.
bool FileExists(string path)
Parameters
pathstringThe path to the file.
Returns
- bool
True if the file exists, otherwise false.
GetCurrentDirectory()
Gets the current working directory of the application.
string GetCurrentDirectory()
Returns
- string
The current directory path.
GetDirectories(string)
Gets the names of subdirectories (including their paths) in the specified directory.
string[] GetDirectories(string path)
Parameters
pathstringThe directory path.
Returns
- string[]
An array of full names of subdirectories.
GetDirectoryName(string)
Gets the directory information for the specified path string.
string? GetDirectoryName(string path)
Parameters
pathstringThe path of a file or directory.
Returns
- string
The directory information, or null if the path does not contain directory information.
GetExtension(string)
Returns the extension (including the period ".") of the specified path string.
string GetExtension(string path)
Parameters
pathstringThe path string from which to get the extension.
Returns
- string
The extension of the specified path (including the period "."), or an empty string if no extension is present.
GetFiles(string, string)
Returns the names of files (including their paths) that match the specified search pattern in the specified directory.
string[] GetFiles(string path, string searchPattern)
Parameters
pathstringThe directory path.
searchPatternstringThe search string to match against the names of files.
Returns
- string[]
An array of the full names of files that match the search pattern.
GetFullPath(string)
Gets the absolute path for the specified path string.
string GetFullPath(string path)
Parameters
pathstringThe relative or absolute path to evaluate.
Returns
- string
The absolute path.
ReadAllText(string)
Reads all text from a file at the specified path.
string ReadAllText(string path)
Parameters
pathstringThe path to the file.
Returns
- string
The content of the file as a string.
ReadAllTextAsync(string, CancellationToken)
Asynchronously reads all text from a file at the specified path.
Task<string> ReadAllTextAsync(string path, CancellationToken cancellationToken = default)
Parameters
pathstringThe path to the file.
cancellationTokenCancellationTokenA token to monitor for cancellation requests.
Returns
WriteAllTextAsync(string, string, CancellationToken)
Asynchronously writes all text to a file at the specified path.
Task WriteAllTextAsync(string path, string contents, CancellationToken cancellationToken = default)
Parameters
pathstringThe path to the file.
contentsstringThe string content to write.
cancellationTokenCancellationTokenA token to monitor for cancellation requests.
Returns
- Task
A task representing the asynchronous operation.