BaseFileSystemclass
A filesystem. Could be on disk, or in memory, or in the cloud. Could be writable or read only. Or it could be an aggregation of all those things, merged together and read only.
Methods24
Showing 24 methods
public void CreateDirectory(string folder)
Create a directory - or a tree of directories. Returns silently if the directory already exists.
| Parameter | Type | Description |
|---|---|---|
| folder | string | — |
void—public Sandbox.BaseFileSystem CreateSubSystem(string path)
Create a sub-filesystem at the specified path
| Parameter | Type | Description |
|---|---|---|
| path | string | — |
public void DeleteDirectory(string folder, bool recursive = False)
Delete a folder and optionally all of its contents
| Parameter | Type | Description |
|---|---|---|
| folder | string | — |
| recursive = False | bool | — |
void—public void DeleteFile(string path)
Delete a file
| Parameter | Type | Description |
|---|---|---|
| path | string | — |
void—public bool DirectoryExists(string path)
Returns true if the directory exists on this filesystem
| Parameter | Type | Description |
|---|---|---|
| path | string | — |
bool—public int DirectorySize(string path, bool recursive = False)
Gets the size in bytes of all the files in a directory
| Parameter | Type | Description |
|---|---|---|
| path | string | — |
| recursive = False | bool | — |
int—public bool FileExists(string path)
Returns true if the file exists on this filesystem
| Parameter | Type | Description |
|---|---|---|
| path | string | — |
bool—public long FileSize(string filepath)
Returns file size of given file.
| Parameter | Type | Description |
|---|---|---|
| filepath | string | File path to the file to look up size of. |
longFile size, in bytes.public System.Collections.Generic.IEnumerable`1<string> FindDirectory(string folder, string pattern = *, bool recursive = False)
Get a list of directories
| Parameter | Type | Description |
|---|---|---|
| folder | string | — |
| pattern = * | string | — |
| recursive = False | bool | — |
IEnumerable<string>—public System.Collections.Generic.IEnumerable`1<string> FindFile(string folder, string pattern = *, bool recursive = False)
Get a list of files
| Parameter | Type | Description |
|---|---|---|
| folder | string | — |
| pattern = * | string | — |
| recursive = False | bool | — |
IEnumerable<string>—public ulong GetCrc(string filepath)
Returns CRC64 of the file contents.
| Parameter | Type | Description |
|---|---|---|
| filepath | string | File path to the file to get CRC of. |
ulongThe CRC64, or 0 if file is not found.public System.Threading.Tasks.Task`1<ulong> GetCrcAsync(string filepath)
Returns CRC64 of the file contents.
| Parameter | Type | Description |
|---|---|---|
| filepath | string | File path to the file to get CRC of. |
Task<ulong>The CRC64, or 0 if file is not found.public string GetFullPath(string path)
Returns the full physical path to a file or folder on disk, or null if it isn't on disk.
| Parameter | Type | Description |
|---|---|---|
| path | string | — |
string—public System.IO.Stream OpenRead(string path, System.IO.FileMode mode = 3)
Open a file for read. Will throw an exception if it doesn't exist.
| Parameter | Type | Description |
|---|---|---|
| path | string | — |
| mode = 3 | FileMode | — |
Stream—public System.IO.Stream OpenWrite(string path, System.IO.FileMode mode = 2)
Open a file for write. If the file exists we'll overwrite it (by default)
| Parameter | Type | Description |
|---|---|---|
| path | string | — |
| mode = 2 | FileMode | — |
Stream—public System.Span`1<byte> ReadAllBytes(string path)
Read the contents of path and return it as a string
| Parameter | Type | Description |
|---|---|---|
| path | string | — |
Span<byte>—public System.Threading.Tasks.Task`1<byte[]> ReadAllBytesAsync(string path)
Read the contents of path and return it as a string
| Parameter | Type | Description |
|---|---|---|
| path | string | — |
Task<byte[]>—public string ReadAllText(string path)
Read the contents of path and return it as a string. Returns null if file not found.
| Parameter | Type | Description |
|---|---|---|
| path | string | — |
string—public System.Threading.Tasks.Task`1<string> ReadAllTextAsync(string path)
Read the contents of path and return it as a string
| Parameter | Type | Description |
|---|---|---|
| path | string | — |
Task<string>—public T ReadJson(string filename, T defaultValue = null)
Read Json from a file using System.Text.Json.JsonSerializer. This will throw exceptions if not valid json.
| Parameter | Type | Description |
|---|---|---|
| filename | string | — |
| defaultValue = null | T | — |
T—public T ReadJsonOrDefault(string filename, T returnOnError = null)
The same as ReadJson except will return a default value on missing/error.
| Parameter | Type | Description |
|---|---|---|
| filename | string | — |
| returnOnError = null | T | — |
T—public void WriteAllBytes(string path, byte[] contents)
Write the contents to the path. The file will be over-written if the file exists
| Parameter | Type | Description |
|---|---|---|
| path | string | — |
| contents | byte[] | — |
void—public void WriteAllText(string path, string contents)
Write the contents to the path. The file will be over-written if the file exists
| Parameter | Type | Description |
|---|---|---|
| path | string | — |
| contents | string | — |
void—public void WriteJson(string filename, T data)
Convert object to json and write it to the specified file
| Parameter | Type | Description |
|---|---|---|
| filename | string | — |
| data | T | — |
void—No results match this filter.
Properties2
Showing 2 properties
public bool Sandbox.BaseFileSystem.IsReadOnly { get; set; }
Returns true if this filesystem is read only
bool—public bool Sandbox.BaseFileSystem.IsValid { get; set; }
bool—No results match this filter.