Api Sandbox BaseFileSystem
class

BaseFileSystem

public class BaseFileSystem

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.

Properties

Name Type Description
IsValid Boolean
IsReadOnly Boolean Returns true if this filesystem is read only

Methods

IEnumerable<String> FindDirectory(String folder, String pattern = *, Boolean recursive = False)

Get a list of directories

IEnumerable<String> FindFile(String folder, String pattern = *, Boolean recursive = False)

Get a list of files

Void DeleteDirectory(String folder, Boolean recursive = False)

Delete a folder and optionally all of its contents

Void DeleteFile(String path)

Delete a file

Void CreateDirectory(String folder)

Create a directory - or a tree of directories. Returns silently if the directory already exists.

folder
Boolean FileExists(String path)

Returns true if the file exists on this filesystem

Boolean DirectoryExists(String path)

Returns true if the directory exists on this filesystem

String GetFullPath(String path)

Returns the full physical path to a file or folder on disk, or null if it isn't on disk.

Void WriteAllText(String path, String contents)

Write the contents to the path. The file will be over-written if the file exists

Void WriteAllBytes(String path, Byte[] contents)

Write the contents to the path. The file will be over-written if the file exists

String ReadAllText(String path)

Read the contents of path and return it as a string. Returns null if file not found.

Span<Byte> ReadAllBytes(String path)

Read the contents of path and return it as a string

Task<Byte[]> ReadAllBytesAsync(String path)

Read the contents of path and return it as a string

Task<String> ReadAllTextAsync(String path)

Read the contents of path and return it as a string

BaseFileSystem CreateSubSystem(String path)

Create a sub-filesystem at the specified path

Stream OpenWrite(String path, FileMode mode = 2)

Open a file for write. If the file exists we'll overwrite it (by default)

Stream OpenRead(String path, FileMode mode = 3)

Open a file for read. Will throw an exception if it doesn't exist.

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.

T ReadJsonOrDefault(String filename, T returnOnError = null)

The same as ReadJson except will return a default value on missing/error.

Void WriteJson(String filename, T data)

Convert object to json and write it to the specified file

Int32 DirectorySize(String path, Boolean recursive = False)

Gets the size in bytes of all the files in a directory

Task<UInt64> GetCrcAsync(String filepath)

Returns CRC64 of the file contents.

filepath — File path to the file to get CRC of.
returns — The CRC64, or 0 if file is not found.
UInt64 GetCrc(String filepath)

Returns CRC64 of the file contents.

filepath — File path to the file to get CRC of.
returns — The CRC64, or 0 if file is not found.
Int64 FileSize(String filepath)

Returns file size of given file.

filepath — File path to the file to look up size of.
returns — File size, in bytes.
Assembly: Sandbox.Filesystem Namespace: Sandbox Full Name: Sandbox.BaseFileSystem