-
Notifications
You must be signed in to change notification settings - Fork 2
Filesystem Module
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.
| FilesystemFile | Handles file read/write operations |
| 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 |
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?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")
endChecks if the path exists and is a file
Core.Filesystem.fileExists(fp: string) -> booleanif Core.Filesystem.fileExists("sdmc:/yourfile.txt") then
--- < your code here >
endChecks if the path exists and is a directory
Core.Filesystem.directoryExists(path: string) -> booleanif Core.Filesystem.directoryExists("sdmc:/path/to/folder") then
--- < your code here >
endIf the directory exists, it will return a table that contains all elements inside that directory
Core.Filesystem.getDirectoryElements(path: string) -> table<string>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:/")Creates the provided directory and returns if success. It will fail if the directory already exists
Core.Filesystem.createDirectory(path: string) -> boolean