FileUtils

This is a helper class to handle file operations in a platform agnostic way.

Enumerations

enum OS_ID:

  • WINDOWS - Windows or UWP

  • MACOS - macOS

  • LINUX - Unix systems (Linux, BSD, etc.)

  • UNSUPPORTED - Any other system currently not supported

Methods

Type

Name

String

test_for_valid_path

void

ensure_path

String

expand_path

int

get_space_left

String

get_folder_size

int

get_file_count

int

get_home_dir

OS_ID

get_os_id

String

get_os_string

bool

is_steam_deck


String test_for_valid_path (paths: String | Array)

Tests whether the supplied path(s) exist in the user’s system. If paths is a String, tests if it exists. Otherwise, if it is a Array, tests for all strings inside and returns the first valid one. Returns "" if no valid path is found.


void ensure_path (path: String)

Recursively creates the directory structure of the specified path, ensuring all subfolders exist

# Creates the directory structure "very/long/folder" if necessary
FileUtils.ensure_path("very/long/folder/my_file.txt")
var file = File.open("very/long/folder/my_file.txt", File.WRITE)
...

String expand_path (path: String)

Expand paths with embedded variables. Supported variables are:

  • ~ - User’s home directory

# Returns C:/Users/<username>/Documents on Windows
FileUtils.expand_path("~/Documents")

int get_space_left ()

Returns the amount of free space, in bytes, of the disk that contains RetroHub’s config directory.


String get_folder_size (path: String, filter_folders: Array = [])

Returns the total size of the specified folder, in bytes. If filter_folders is specified, it will not count the size of any folder that matches any of the strings in the array.


int get_file_count (path: String, filter_folders: Array = [])

Returns the total number of files in the specified folder. If filter_folders is specified, it will not count any files inside a folder that matches any of the strings in the array.


String get_home_dir ()

Returns the user’s home directory.


OS_ID get_os_id ()

Returns the current operating system as an OS_ID.


String get_os_string ()

Returns the current operating system as a string. Possible values are "windows", "macos", "linux", and "null".


bool is_steam_deck ()

Returns true if the current system is a Steam Deck.