Skip to content

Filesystem Module

STBrian edited this page Oct 28, 2025 · 6 revisions

The Filesystem submodule contains functions related to folders and files from the sdcard or the game extdata. You can access sdcard by using sdmc:/ prefix at the start of a path, or extdata:/ to access game extdata

Note: If the game has not yet created the extdata, it will not work until the next game launch.

Types

FilesystemFile Handles file read/write operations

Functions

Core.Filesystem.open Opens a file
Core.Filesystem.fileExists Checks if the file exists
Core.Filesystem.directoryExists Checks if the directory exists
Core.Filesystem.getDirectoryElements Returns a table with directory elements
Core.Filesystem.createDirectory Creates the directory if not exists

Core.Filesystem.open

Opens a file. Returns nil if the file wasn't opened with an error message. It will return a FilesystemFile object that contains methods that you can use to read or write to the file. Check FilesystemFile methods.

Core.Filesystem.open(fp: string, mode: string) -> FilesystemFile?, string?

Example

local optionsFile = Core.Filesystem.open("extdata:/options.txt", "r")
if optionsFile then -- Checks that optionsFile is not nil, in other words, that the file opened successfully
    --- < your code here >
else
    Core.Debug.message("Failed to open extdata:/options.txt")
end

Core.Filesystem.fileExists

Checks if the path exists and is a file

Core.Filesystem.fileExists(fp: string) -> boolean

Example

if Core.Filesystem.fileExists("sdmc:/yourfile.txt") then
    --- < your code here >
end

Core.Filesystem.directoryExists

Checks if the path exists and is a directory

Core.Filesystem.directoryExists(path: string) -> boolean

Example

if Core.Filesystem.directoryExists("sdmc:/path/to/folder") then
    --- < your code here >
end

Core.Filesystem.getDirectoryElements

If the directory exists, it will return a table that contains all elements inside that directory

Core.Filesystem.getDirectoryElements(path: string) -> table<string>

Example

local function iterateRDir(path)
    local elements = Core.Filesystem.getDirectoryElements(path)
    for index, value in ipairs(elements) do
        Core.Debug.message(path..value)
        if Core.Filesystem.directoryExists(path..value) then -- directoryExists can also be used to detect if a path is a directory
            iterateRDir(path..value.."/")
        end
    end
end

iterateRDir("extdata:/")

Core.Filesystem.createDirectory

Creates the provided directory and returns if success. It will fail if the directory already exists

Core.Filesystem.createDirectory(path: string) -> boolean

Clone this wiki locally