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.
Related Guides
Broader workflow and conceptual references connected to this API.
Standard .NET file access is restricted to prevent rogue access to your files, this means you can not use System.IO.File or variants directly.
The Storage system provides a simple, unified way to manage user-generated content in your game. Whether you're saving game progress, storing player creations, or anything else, Storage handles everything from local file management to Steam Workshop integration.
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
No results match this filter.
Properties
Showing 2 properties
public bool Sandbox.BaseFileSystem.IsReadOnly { get; set; }
Returns true if this filesystem is read only
public bool Sandbox.BaseFileSystem.IsValid { get; set; }
No results match this filter.
Metadata
| Field | Value |
|---|---|
| Namespace | Sandbox |
| Type | class |
| Assembly | Sandbox.Filesystem |
| Doc ID | T:Sandbox.BaseFileSystem |