s&box docs

public class Sandbox.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.

Broader workflow and conceptual references connected to this API.

Methods

Showing 24 methods

public void CreateDirectory(string folder)

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

public Sandbox.BaseFileSystem CreateSubSystem(string path)

Create a sub-filesystem at the specified path

public void DeleteDirectory(string folder, bool recursive = False)

Delete a folder and optionally all of its contents

Parameters

  • recursive: Default: False

public void DeleteFile(string path)

Delete a file

public bool DirectoryExists(string path)

Returns true if the directory exists on this filesystem

public int DirectorySize(string path, bool recursive = False)

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

Parameters

  • recursive: Default: False

public bool FileExists(string path)

Returns true if the file exists on this filesystem

public long FileSize(string filepath)

Returns file size of given file.

Parameters

  • filepath: File path to the file to look up size of.

Returns

File size, in bytes.

public System.Collections.Generic.IEnumerable`1<string> FindDirectory(string folder, string pattern = *, bool recursive = False)

Get a list of directories

Parameters

  • pattern: Default: *
  • recursive: Default: False

public System.Collections.Generic.IEnumerable`1<string> FindFile(string folder, string pattern = *, bool recursive = False)

Get a list of files

Parameters

  • pattern: Default: *
  • recursive: Default: False

public ulong GetCrc(string filepath)

Returns CRC64 of the file contents.

Parameters

  • filepath: File path to the file to get CRC of.

Returns

The CRC64, or 0 if file is not found.

public System.Threading.Tasks.Task`1<ulong> GetCrcAsync(string filepath)

Returns CRC64 of the file contents.

Parameters

  • filepath: File path to the file to get CRC of.

Returns

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.

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.

Parameters

  • mode: Default: 3

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)

Parameters

  • mode: Default: 2

public System.Span`1<byte> ReadAllBytes(string path)

Read the contents of path and return it as a string

public System.Threading.Tasks.Task`1<byte[]> ReadAllBytesAsync(string path)

Read the contents of path and return it as a string

public string ReadAllText(string path)

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

public System.Threading.Tasks.Task`1<string> ReadAllTextAsync(string path)

Read the contents of path and return it as a 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.

Parameters

  • defaultValue: Default: null

public T ReadJsonOrDefault(string filename, T returnOnError = null)

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

Parameters

  • returnOnError: Default: null

public void WriteAllBytes(string path, byte[] contents)

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

public void WriteAllText(string path, string contents)

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

public void WriteJson(string filename, T data)

Convert object to json and write it to the specified file

Properties

Showing 2 properties

public bool Sandbox.BaseFileSystem.IsReadOnly { get; set; }

Returns true if this filesystem is read only

Metadata

FieldValue
NamespaceSandbox
Typeclass
AssemblySandbox.Filesystem
Doc IDT:Sandbox.BaseFileSystem

On this page

Methodspublic System.Void CreateDirectory(System.String folder)public Sandbox.BaseFileSystem CreateSubSystem(System.String path)public System.Void DeleteDirectory(System.String folder, System.Boolean recursive = False)public System.Void DeleteFile(System.String path)public System.Boolean DirectoryExists(System.String path)public System.Int32 DirectorySize(System.String path, System.Boolean recursive = False)public System.Boolean FileExists(System.String path)public System.Int64 FileSize(System.String filepath)public System.Collections.Generic.IEnumerable`1<System.String> FindDirectory(System.String folder, System.String pattern = *, System.Boolean recursive = False)public System.Collections.Generic.IEnumerable`1<System.String> FindFile(System.String folder, System.String pattern = *, System.Boolean recursive = False)public System.UInt64 GetCrc(System.String filepath)public System.Threading.Tasks.Task`1<System.UInt64> GetCrcAsync(System.String filepath)public System.String GetFullPath(System.String path)public System.IO.Stream OpenRead(System.String path, System.IO.FileMode mode = 3)public System.IO.Stream OpenWrite(System.String path, System.IO.FileMode mode = 2)public System.Span`1<System.Byte> ReadAllBytes(System.String path)public System.Threading.Tasks.Task`1<System.Byte[]> ReadAllBytesAsync(System.String path)public System.String ReadAllText(System.String path)public System.Threading.Tasks.Task`1<System.String> ReadAllTextAsync(System.String path)public T ReadJson(System.String filename, T defaultValue = null)public T ReadJsonOrDefault(System.String filename, T returnOnError = null)public System.Void WriteAllBytes(System.String path, System.Byte[] contents)public System.Void WriteAllText(System.String path, System.String contents)public System.Void WriteJson(System.String filename, T data)Propertiespublic System.Boolean Sandbox.BaseFileSystem.IsReadOnly { get; set; }public System.Boolean Sandbox.BaseFileSystem.IsValid { get; set; }Metadata