FileSystemModule
FileSystem
IFileSystem makes file access an explicit, mockable dependency. Every operation returns
Flow<'env, FileSystemError, _> and fails with FileSystemError
rather than throwing. Read the FileSystem guide for supplying the service and
representative usage; this page is the operation catalog.
Whole-file reads and writes
Whole-file reads and writes come in text, line, and byte forms, each with an encoding-explicit and an asynchronous
variant: readAllTextWithEncoding, readAllTextAsync, readAllBytes, writeAllBytes, and the rest of the
readAllText, readAllLines, writeAllLines, writeAllText, appendAllText, and appendAllLines family.
The Async members on IFileSystem (including ReadAllTextAsync, ReadAllBytesAsync, and
WriteAllTextAsync) have signatures such as
ReadAllTextAsync : path: string -> Flow<unit, FileSystemError, string> — no token argument, and an environment
type of unit. The FileSystem module functions you call from a workflow (FileSystem.readAllTextAsync,
FileSystem.readAllBytesAsync, FileSystem.writeAllTextAsync, and the rest) wrap those members, so they return
Flow<'env, FileSystemError, _> with when 'env :> IHasFileSystem. The runtime passes its cancellation token to the
underlying I/O, so interrupting a workflow stops a large read in progress.
Files and metadata
fileExists, exists, deleteFile, copyFile, and moveFile cover the other common operations.
getFileLength returns a file's size in bytes. File metadata has getters and setters for attributes and the
creation, last-access, and last-write times in both local and UTC forms, such as getFileLastWriteTimeUtc,
setFileAttributes, and so on.
Symbolic links are first class: createFileSymbolicLink, createDirectorySymbolicLink, getSymbolicLinkTarget
(which returns None when the path is not a link), and resolveSymbolicLinkTarget, whose boolean argument decides
whether to follow the whole chain or stop at the immediate target.
Streams and scopes
openRead, openText, openWrite, createFile, createText, appendText, and the openFile family return open
handles. Acquire open handles inside a scope to ensure disposal; see
scopes and resources.
Directories and paths
createDirectory creates missing parents. deleteDirectory path recursive takes the recursion flag explicitly, so a
recursive delete is visible at the call site. Listing comes in eager (getFiles, getDirectories,
getFileSystemEntries) and lazy (enumerateFiles, enumerateDirectories, enumerateFileSystemEntries) forms, each
taking a search pattern and a SearchOption. enumerateFileSystemInfos directory pattern searchOption yields
FileSystemEntry values with path, kind, size, and timestamps in one listing, avoiding separate metadata calls per
entry.
Path manipulation is also on the service: combine, getFullPath, getFileName, getExtension, getRelativePath,
getTempPath, getRandomFileName, and the rest. These are pure string operations on .NET, but routing them through
the service keeps platform-specific separator and rooting behaviour substitutable in tests.
Summary
| Name | Signature | Synopsis |
|---|---|---|
| Operations | ||
| service | FileSystem.service | Reads the file-system service from the environment. |
| readAllText | FileSystem.readAllText path | Reads all text through an explicit file-system service. |
| readAllTextWithEncoding | FileSystem.readAllTextWithEncoding encoding path | Reads all text with the specified encoding through an explicit file-system service. |
| readAllTextAsync | FileSystem.readAllTextAsync path | Asynchronously reads all text through an explicit file-system service. |
| readAllLines | FileSystem.readAllLines path | Reads all lines through an explicit file-system service. |
| readAllLinesWithEncoding | FileSystem.readAllLinesWithEncoding encoding path | Reads all lines with the specified encoding through an explicit file-system service. |
| readAllLinesAsync | FileSystem.readAllLinesAsync path | Asynchronously reads all lines through an explicit file-system service. |
| readAllBytes | FileSystem.readAllBytes path | Reads all bytes through an explicit file-system service. |
| readAllBytesAsync | FileSystem.readAllBytesAsync path | Asynchronously reads all bytes through an explicit file-system service. |
| writeAllText | FileSystem.writeAllText path contents | Writes all text through an explicit file-system service. |
| writeAllTextWithEncoding | FileSystem.writeAllTextWithEncoding encoding path contents | Writes all text with the specified encoding through an explicit file-system service. |
| writeAllTextAsync | FileSystem.writeAllTextAsync path contents | Asynchronously writes all text through an explicit file-system service. |
| writeAllLines | FileSystem.writeAllLines path contents | Writes all lines through an explicit file-system service. |
| writeAllLinesWithEncoding | FileSystem.writeAllLinesWithEncoding encoding path contents | Writes all lines with the specified encoding through an explicit file-system service. |
| writeAllLinesAsync | FileSystem.writeAllLinesAsync path contents | Asynchronously writes all lines through an explicit file-system service. |
| writeAllBytes | FileSystem.writeAllBytes path contents | Writes all bytes through an explicit file-system service. |
| writeAllBytesAsync | FileSystem.writeAllBytesAsync path contents | Asynchronously writes all bytes through an explicit file-system service. |
| appendAllText | FileSystem.appendAllText path contents | Appends all text through an explicit file-system service. |
| appendAllTextWithEncoding | FileSystem.appendAllTextWithEncoding encoding path contents | Appends all text with the specified encoding through an explicit file-system service. |
| appendAllTextAsync | FileSystem.appendAllTextAsync path contents | Asynchronously appends all text through an explicit file-system service. |
| appendAllLines | FileSystem.appendAllLines path contents | Appends all lines through an explicit file-system service. |
| appendAllLinesWithEncoding | FileSystem.appendAllLinesWithEncoding encoding path contents | Appends all lines with the specified encoding through an explicit file-system service. |
| fileExists | FileSystem.fileExists path | Checks file existence through an explicit file-system service. |
| exists | FileSystem.exists path | Checks file existence through an explicit file-system service. |
| deleteFile | FileSystem.deleteFile path | Deletes a file through an explicit file-system service. |
| copyFile | FileSystem.copyFile sourcePath destinationPath overwrite | Copies a file through an explicit file-system service. |
| moveFile | FileSystem.moveFile sourcePath destinationPath overwrite | Moves a file through an explicit file-system service. |
| createFileSymbolicLink | FileSystem.createFileSymbolicLink linkPath targetPath | Creates a symbolic link to a file through an explicit file-system service. |
| createDirectorySymbolicLink | FileSystem.createDirectorySymbolicLink linkPath targetPath | Creates a symbolic link to a directory through an explicit file-system service. |
| getSymbolicLinkTarget | FileSystem.getSymbolicLinkTarget path | Returns the immediate target stored in a symbolic link. |
| resolveSymbolicLinkTarget | FileSystem.resolveSymbolicLinkTarget returnFinalTarget path | Resolves a symbolic link target, optionally following the complete chain. |
| openFile | FileSystem.openFile mode path | Opens a file with the specified mode through an explicit file-system service. |
| openFileWithAccess | FileSystem.openFileWithAccess mode access path | Opens a file with the specified mode and access through an explicit file-system service. |
| openFileWithShare | FileSystem.openFileWithShare mode access share path | Opens a file with the specified mode, access, and sharing behavior through an explicit file-system service. |
| openRead | FileSystem.openRead path | Opens a file for reading through an explicit file-system service. |
| openText | FileSystem.openText path | Opens a text reader through an explicit file-system service. |
| openWrite | FileSystem.openWrite path | Opens a file for writing through an explicit file-system service. |
| createFile | FileSystem.createFile path | Creates or overwrites a file through an explicit file-system service. |
| createText | FileSystem.createText path | Creates a text writer through an explicit file-system service. |
| appendText | FileSystem.appendText path | Creates an append text writer through an explicit file-system service. |
| getFileLength | FileSystem.getFileLength path | Gets the size of a file in bytes through an explicit file-system service. |
| getFileAttributes | FileSystem.getFileAttributes path | Gets file attributes through an explicit file-system service. |
| setFileAttributes | FileSystem.setFileAttributes path attributes | Sets file attributes through an explicit file-system service. |
| getFileCreationTime | FileSystem.getFileCreationTime path | Gets file creation time through an explicit file-system service. |
| getFileCreationTimeUtc | FileSystem.getFileCreationTimeUtc path | Gets file creation time in UTC through an explicit file-system service. |
| setFileCreationTime | FileSystem.setFileCreationTime path time | Sets file creation time through an explicit file-system service. |
| setFileCreationTimeUtc | FileSystem.setFileCreationTimeUtc path time | Sets file creation time in UTC through an explicit file-system service. |
| getFileLastAccessTime | FileSystem.getFileLastAccessTime path | Gets file last access time through an explicit file-system service. |
| getFileLastAccessTimeUtc | FileSystem.getFileLastAccessTimeUtc path | Gets file last access time in UTC through an explicit file-system service. |
| setFileLastAccessTime | FileSystem.setFileLastAccessTime path time | Sets file last access time through an explicit file-system service. |
| setFileLastAccessTimeUtc | FileSystem.setFileLastAccessTimeUtc path time | Sets file last access time in UTC through an explicit file-system service. |
| getFileLastWriteTime | FileSystem.getFileLastWriteTime path | Gets file last write time through an explicit file-system service. |
| getFileLastWriteTimeUtc | FileSystem.getFileLastWriteTimeUtc path | Gets file last write time in UTC through an explicit file-system service. |
| setFileLastWriteTime | FileSystem.setFileLastWriteTime path time | Sets file last write time through an explicit file-system service. |
| setFileLastWriteTimeUtc | FileSystem.setFileLastWriteTimeUtc path time | Sets file last write time in UTC through an explicit file-system service. |
| directoryExists | FileSystem.directoryExists path | Checks directory existence through an explicit file-system service. |
| createDirectory | FileSystem.createDirectory path | Creates a directory through an explicit file-system service. |
| deleteDirectory | FileSystem.deleteDirectory path recursive | Deletes a directory through an explicit file-system service. |
| moveDirectory | FileSystem.moveDirectory sourcePath destinationPath | Moves a directory through an explicit file-system service. |
| enumerateFiles | FileSystem.enumerateFiles path searchPattern searchOption | Enumerates files through an explicit file-system service. |
| getFiles | FileSystem.getFiles path searchPattern searchOption | Gets files through an explicit file-system service. |
| enumerateDirectories | FileSystem.enumerateDirectories path searchPattern searchOption | Enumerates directories through an explicit file-system service. |
| getDirectories | FileSystem.getDirectories path searchPattern searchOption | Gets directories through an explicit file-system service. |
| enumerateFileSystemEntries | FileSystem.enumerateFileSystemEntries path searchPattern searchOption | Enumerates files and directories through an explicit file-system service. |
| enumerateFileSystemInfos | FileSystem.enumerateFileSystemInfos path searchPattern searchOption | Enumerates files and directories with metadata through the file-system service. |
| getFileSystemEntries | FileSystem.getFileSystemEntries path searchPattern searchOption | Gets files and directories through an explicit file-system service. |
| getLogicalDrives | FileSystem.getLogicalDrives | Gets logical drives through an explicit file-system service. |
| getDirectoryRoot | FileSystem.getDirectoryRoot path | Gets the directory root through an explicit file-system service. |
| getParent | FileSystem.getParent path | Gets the parent directory through an explicit file-system service. |
| getCurrentDirectory | FileSystem.getCurrentDirectory | Gets the current working directory through an explicit file-system service. |
| setCurrentDirectory | FileSystem.setCurrentDirectory path | Sets the current working directory through an explicit file-system service. |
| getDirectoryCreationTime | FileSystem.getDirectoryCreationTime path | Gets directory creation time through an explicit file-system service. |
| getDirectoryCreationTimeUtc | FileSystem.getDirectoryCreationTimeUtc path | Gets directory creation time in UTC through an explicit file-system service. |
| setDirectoryCreationTime | FileSystem.setDirectoryCreationTime path time | Sets directory creation time through an explicit file-system service. |
| setDirectoryCreationTimeUtc | FileSystem.setDirectoryCreationTimeUtc path time | Sets directory creation time in UTC through an explicit file-system service. |
| getDirectoryLastAccessTime | FileSystem.getDirectoryLastAccessTime path | Gets directory last access time through an explicit file-system service. |
| getDirectoryLastAccessTimeUtc | FileSystem.getDirectoryLastAccessTimeUtc path | Gets directory last access time in UTC through an explicit file-system service. |
| setDirectoryLastAccessTime | FileSystem.setDirectoryLastAccessTime path time | Sets directory last access time through an explicit file-system service. |
| setDirectoryLastAccessTimeUtc | FileSystem.setDirectoryLastAccessTimeUtc path time | Sets directory last access time in UTC through an explicit file-system service. |
| getDirectoryLastWriteTime | FileSystem.getDirectoryLastWriteTime path | Gets directory last write time through an explicit file-system service. |
| getDirectoryLastWriteTimeUtc | FileSystem.getDirectoryLastWriteTimeUtc path | Gets directory last write time in UTC through an explicit file-system service. |
| setDirectoryLastWriteTime | FileSystem.setDirectoryLastWriteTime path time | Sets directory last write time through an explicit file-system service. |
| setDirectoryLastWriteTimeUtc | FileSystem.setDirectoryLastWriteTimeUtc path time | Sets directory last write time in UTC through an explicit file-system service. |
| combine | FileSystem.combine paths | Combines path segments through an explicit file-system service. |
| changeExtension | FileSystem.changeExtension path extension | Changes a path extension through an explicit file-system service. |
| getDirectoryName | FileSystem.getDirectoryName path | Gets the directory name for a path through an explicit file-system service. |
| getInvalidFileNameChars | FileSystem.getInvalidFileNameChars | Gets invalid file-name characters through an explicit file-system service. |
| getInvalidPathChars | FileSystem.getInvalidPathChars | Gets invalid path characters through an explicit file-system service. |
| getExtension | FileSystem.getExtension path | Gets the extension for a path through an explicit file-system service. |
| getFileName | FileSystem.getFileName path | Gets the file name for a path through an explicit file-system service. |
| getFileNameWithoutExtension | FileSystem.getFileNameWithoutExtension path | Gets the file name without extension for a path through an explicit file-system service. |
| getFullPath | FileSystem.getFullPath path | Gets the full path through an explicit file-system service. |
| getPathRoot | FileSystem.getPathRoot path | Gets the path root through an explicit file-system service. |
| getRelativePath | FileSystem.getRelativePath relativeTo path | Gets a relative path through an explicit file-system service. |
| getTempPath | FileSystem.getTempPath | Gets the temporary directory path through an explicit file-system service. |
| getTempFileName | FileSystem.getTempFileName | Creates a temporary file through an explicit file-system service and returns its path. |
| getRandomFileName | FileSystem.getRandomFileName | Gets a random file name through an explicit file-system service. |
| hasExtension | FileSystem.hasExtension path | Checks whether a path has an extension through an explicit file-system service. |
| endsInDirectorySeparator | FileSystem.endsInDirectorySeparator path | Checks whether a path ends in a directory separator through an explicit file-system service. |
| trimEndingDirectorySeparator | FileSystem.trimEndingDirectorySeparator path | Trims one trailing directory separator through an explicit file-system service. |
| isPathFullyQualified | FileSystem.isPathFullyQualified path | Checks whether a path is fully qualified through an explicit file-system service. |
| isPathRooted | FileSystem.isPathRooted path | Checks whether a path is rooted through an explicit file-system service. |
| live | FileSystem.live | Creates a live file-system service backed by File, Directory, and Path. |
| test | FileSystem.test () | Creates an empty in-memory file-system test double; seed via the TestFileSystem constructor. |
Operations
Parameters
| Name | Type | Description |
|---|---|---|
| linkPath | string | |
| targetPath | string |
Returns
Verification Examples
FileSystem.createFileSymbolicLink "current.json" "releases/v2.json"Parameters
| Name | Type | Description |
|---|---|---|
| linkPath | string | |
| targetPath | string |
Returns
Verification Examples
FileSystem.createDirectorySymbolicLink "current" "releases/v2"Parameters
| Name | Type | Description |
|---|---|---|
| returnFinalTarget | bool | |
| path | string |
Returns
Verification Examples
FileSystem.resolveSymbolicLinkTarget true "current"Parameters
| Name | Type | Description |
|---|---|---|
| mode | FileMode | |
| access | FileAccess | |
| share | FileShare | |
| path | string |
Returns
Parameters
| Name | Type | Description |
|---|---|---|
| path | string | |
| searchPattern | string | |
| searchOption | SearchOption |
Returns
Parameters
| Name | Type | Description |
|---|---|---|
| path | string | |
| searchPattern | string | |
| searchOption | SearchOption |

