Skip to content

FsService

Version: >= 0.2.0

File system service object for managing file system related operations.

Can be constructed via fs:new.

Methods

obj:request_access(options: RequestAccessOptions) -> List<string>

Parameters: RequestAccessOptions

Returns: List of paths.

Requests file access permissions. This will open a system file selection dialog, allowing the user to select files to access, and returns the selected file paths list.

The file selection process serves as the authorization process - only authorized files or directories can be accessed through subsequent operations.

Authorization lifecycle: Takes effect from authorization until script reload ends.

obj:read_text_file(path: string) -> string

Requires r permission.

Reads text file content.

obj:write_text_file(path: string, data: string)

Requires w permission.

Writes string content to file. If the path doesn't exist, it will create folders and files. If the file exists, it will overwrite the original file.

obj:mkdir(path: string, recursive: bool)

Added in 0.3.0

Requires w permission.

Creates a directory. If recursive is true, it will create the directory and its subdirectories.

obj:remove(path: string)

Added in 0.3.0

Requires w permission.

Removes a file or directory.

obj:read_dir(path: string) -> (List<string>, List<string>)

Added in 0.3.0

Returns: (directories, files)

Requires r permission.

Reads the contents of a directory. Returns a tuple of directories and files.

RequestAccessOptions

Field NameTypeDefaultDescription
permissionstringRequired, permission type, options are "r", "w", "rw"
directorystring"."Default selected directory path
file_namestring""Default selected filename
filtersList<DialogFilter>NoneFile extension filters
titlestring""Dialog title
folderboolfalseFolder selection mode
multipleboolfalseWhether multiple files can be selected
recursiveboolfalseWhether to recursively grant directory permissions (only when folder is true): if true, grants access to the directory and its subdirectories
auto_grantboolfalseWhether to auto-grant permissions (only when multiple is false): if true, no dialog will pop up if the directory already has permissions

DialogFilter

Field NameTypeDescription
namestringRequired, name
extensionsList<string>Required, extensions