menu_bookDocumentation

FileSystem: Mounted, Data, OrganizationData, Cache, and Memory Filesystems

calendar_today May 4, 2026 schedule ~1 min read person patrickjr verified 50

FileSystem: Accessing Game Files in s&box

s&box provides several filesystem access points through the static FileSystem class.

Available Filesystems

| Property | Description | |---|---| | FileSystem.Mounted | All mounted content (game files, addons, etc.) | | FileSystem.Data | Custom data for the current gamemode | | FileSystem.OrganizationData | Custom data per gamemode's organization | | FileSystem.Cache | A global key-value cache (may be deleted at any time) |

Reading and Writing Files

CSHARP
// Read text
string text = FileSystem.Data.ReadAllText( "config.json" );

// Write text
FileSystem.Data.WriteAllText( "config.json", jsonString );

// Read bytes
byte[] data = FileSystem.Data.ReadAllBytes( "data.bin" );

// Write bytes
FileSystem.Data.WriteAllBytes( "data.bin", bytes );

// Check existence
bool exists = FileSystem.Data.FileExists( "config.json" );

// Create directory
FileSystem.Data.CreateDirectory( "saves" );

// List files
var files = FileSystem.Data.FindFile( "saves", "*.json" );

KeyStore Cache

FileSystem.Cache is a key-value store backed by MD5-hashed filenames. Useful for caching computed data:
CSHARP
// Store data by key
FileSystem.Cache.Set( "my_computed_data", bytes );

// Retrieve data
if ( FileSystem.Cache.TryGet( "my_computed_data", out var cached ) )
{
    // use cached
}

// Check existence
bool exists = FileSystem.Cache.Exists( "my_computed_data" );

// Remove
FileSystem.Cache.Remove( "my_computed_data" );
The cache is stored in /.source2/cache/ and can be deleted at any time without breaking anything.

Memory Filesystem

CSHARP
// Create an in-memory filesystem (useful for testing or temporary data)
var memFs = FileSystem.CreateMemoryFileSystem();
memFs.WriteAllText( "temp.txt", "hello" );
Was this helpful?