Skip to content

Class: FS

Engine filesystem facade.

Path aliases such as $game_config$ and $logs$ are resolved by this object.

Source

C++ class FS

Custom Constructor

FS

Remarks

Mutating methods operate on real files or engine path aliases. Prefer exist, path_exist, and update_path before destructive operations.

Constructors

Constructor

ts
new FS(): FS;

Returns

FS

Methods

append_path()

ts
append_path(
   alias: string, 
   root: string, 
   path: string, 
   recursive: boolean): FS_Path;

Add a path alias.

Parameters

ParameterTypeDescription
aliasstringAlias name.
rootstringRoot path.
pathstringRelative path.
recursivebooleanWhether subfolders should be scanned.

Returns

FS_Path

Native filesystem path descriptor.

Remarks

Native code asserts if root is invalid or alias is already registered. On success it returns a path descriptor.


dir_delete()

Call Signature

ts
dir_delete(
   path: string, 
   filename: string, 
   remove_files: boolean): void;

Delete a directory below a path alias.

Parameters
ParameterTypeDescription
pathstringPath alias or root path.
filenamestringDirectory name.
remove_filesbooleanWhether files inside should be removed.
Returns

void

Call Signature

ts
dir_delete(path: string, remove_files: boolean): void;

Delete a directory.

Parameters
ParameterTypeDescription
pathstringDirectory path.
remove_filesbooleanWhether files inside should be removed.
Returns

void


exist()

Call Signature

ts
exist(
   alias: string, 
   filename: string, 
   fs_type: TXR_fs_type): FileStatus;

Check whether a file exists below a path alias in a selected filesystem source.

Parameters
ParameterTypeDescription
aliasstringFilesystem path alias.
filenamestringFile name.
fs_typeTXR_fs_typeFilesystem source to search.
Returns

FileStatus

File status.

Since

OpenXRay 2014-11-02, 827c9f58

Remarks

OpenXRay extension. This overload resolves alias and filename, then checks virtual files, external files, or both according to fs_type. It always returns a FileStatus; inspect Exists for the result and External to see whether the match came from the external filesystem.

Call Signature

ts
exist(alias: string, filename: string): Nullable<fs_file>;

Get a registered file descriptor below a path alias.

Parameters
ParameterTypeDescription
aliasstringFilesystem path alias.
filenamestringFile name.
Returns

Nullable<fs_file>

Registered file descriptor, or null when no registered file is found.

Remarks

Original X-Ray/vanilla-compatible overload. It resolves alias and filename and searches registered virtual files only.

Call Signature

ts
exist(path: string): Nullable<fs_file>;

Get a registered file descriptor by full virtual path.

Parameters
ParameterTypeDescription
pathstringFile path.
Returns

Nullable<fs_file>

Registered file descriptor, or null when no registered file is found.

Remarks

Original X-Ray/vanilla-compatible overload. It searches registered virtual files only. OpenXRay restored this overload on 2023-01-25 after external-filesystem overloads had temporarily taken the exist name.

Call Signature

ts
exist(path: string, fs_type: TXR_fs_type): FileStatus;

Check whether a file exists in a selected filesystem source.

Parameters
ParameterTypeDescription
pathstringFile path.
fs_typeTXR_fs_typeFilesystem source to search.
Returns

FileStatus

File status.

Since

OpenXRay 2014-11-02, 827c9f58

Remarks

OpenXRay extension. This overload checks virtual files, external files, or both according to fs_type. It always returns a FileStatus; inspect Exists for the result and External to see whether the match came from the external filesystem.


file_copy()

ts
file_copy(source: string, destination: string): void;

Copy a file.

Parameters

ParameterTypeDescription
sourcestringSource file path.
destinationstringDestination file path.

Returns

void


file_delete()

Call Signature

ts
file_delete(path: string, filename: string): void;

Delete a file below a path alias.

Parameters
ParameterTypeDescription
pathstringPath alias or root path.
filenamestringFile name.
Returns

void

Call Signature

ts
file_delete(path: string): void;

Delete a file.

Parameters
ParameterTypeDescription
pathstringFile path.
Returns

void


file_length()

ts
file_length(path: string): number;

Get file length.

Parameters

ParameterTypeDescription
pathstringFile path.

Returns

number

File length in bytes, or engine error value.


file_list_open()

Call Signature

ts
file_list_open(
   alias: string, 
   folder: string, 
   flags: number): FS_file_list;

Open a file list below a path alias and folder.

Parameters
ParameterTypeDescription
aliasstringFilesystem path alias.
folderstringFolder inside the alias.
flagsnumberListing flags.
Returns

FS_file_list

File list.

Call Signature

ts
file_list_open(path: string, flags: number): FS_file_list;

Open a file list for a resolved path or alias.

Parameters
ParameterTypeDescription
pathstringPath or path alias.
flagsnumberListing flags.
Returns

FS_file_list

File list.


file_list_open_ex()

ts
file_list_open_ex(
   path: string, 
   flags: number, 
   mask: string): FS_file_list_ex;

Open a sortable filtered file list.

Parameters

ParameterTypeDescription
pathstringPath or path alias.
flagsnumberListing flags.
maskstringFile mask.

Returns

FS_file_list_ex

Sortable file list.

Remarks

Forces the path to be rescanned before collecting matching entries.


file_rename()

ts
file_rename(
   path: string, 
   destination: string, 
   overwrite: boolean): void;

Rename or move a file.

Parameters

ParameterTypeDescription
pathstringSource file path.
destinationstringDestination file path.
overwritebooleanWhether an existing destination may be overwritten.

Returns

void


get_file_age()

ts
get_file_age(path: string): number;

Get file modification timestamp.

Parameters

ParameterTypeDescription
pathstringFile path.

Returns

number

Modification timestamp.


get_file_age_str()

ts
get_file_age_str(path: string): number;

Get file modification timestamp as packed display value.

Parameters

ParameterTypeDescription
pathstringFile path.

Returns

number

Modification timestamp value.


get_path()

ts
get_path(alias: string): FS_Path;

Get native path descriptor for an alias.

Parameters

ParameterTypeDescription
aliasstringFilesystem path alias.

Returns

FS_Path

Native filesystem path descriptor.

Remarks

Native code asserts when the alias is missing. Use FS.path_exist before calling when the alias is optional.


path_exist()

ts
path_exist(path: string): boolean;

Check whether a path alias exists.

Parameters

ParameterTypeDescription
pathstringPath alias.

Returns

boolean

Whether the path exists.


r_close()

ts
r_close(reader: reader): void;

Close a binary reader.

Parameters

ParameterTypeDescription
readerreaderReader returned by r_open.

Returns

void


r_open()

Call Signature

ts
r_open(path: string): reader;

Open a binary reader.

Parameters
ParameterTypeDescription
pathstringFile path.
Returns

reader

Binary reader.

Call Signature

ts
r_open(alias: string, path: string): reader;

Open a binary reader below a path alias.

Parameters
ParameterTypeDescription
aliasstringFilesystem path alias.
pathstringRelative file path.
Returns

reader

Binary reader.


rescan_path()

ts
rescan_path(path: string): void;

Rescan a path alias.

Parameters

ParameterTypeDescription
pathstringPath alias.

Returns

void

Since

OpenXRay 2015-07-07, 6e703b4c

Remarks

Marks the alias as needing a rescan. The next filesystem check refreshes cached entries.


update_path()

ts
update_path(alias: string, add: string): string;

Resolve path alias and suffix into a real path.

Parameters

ParameterTypeDescription
aliasstringFilesystem path alias.
addstringRelative path to append.

Returns

string

Resolved path.

Remarks

Non-Windows builds normalize path separators before returning the string.


w_close()

ts
w_close(writer: Nillable<IWriter>): void;

Close a binary writer.

Parameters

ParameterTypeDescription
writerNillable<IWriter>Writer returned by w_open.

Returns

void


w_open()

Call Signature

ts
w_open(path: string, filename: string): Nullable<IWriter>;

Open a binary writer below a path alias.

Parameters
ParameterTypeDescription
pathstringFilesystem path alias.
filenamestringRelative file path.
Returns

Nullable<IWriter>

Binary writer, or null.

Remarks

Can return null when native writer setup fails.

Call Signature

ts
w_open(path: string): Nullable<IWriter>;

Open a binary writer.

Parameters
ParameterTypeDescription
pathstringFile path.
Returns

Nullable<IWriter>

Binary writer, or null.

Remarks

Can return null when native writer setup fails.

Properties

FS_ClampExt

ts
readonly static FS_ClampExt: 4;

Clamp listed paths by extension.


FS_ListFiles

ts
readonly static FS_ListFiles: 1;

List files.


FS_ListFolders

ts
readonly static FS_ListFolders: 2;

List folders.


FS_RootOnly

ts
readonly static FS_RootOnly: 8;

Do not recurse into subfolders.


FS_sort_by_modif_down

ts
readonly static FS_sort_by_modif_down: 5;

Sort by modification time, newest first.


FS_sort_by_modif_up

ts
readonly static FS_sort_by_modif_up: 4;

Sort by modification time, oldest first.


FS_sort_by_name_down

ts
readonly static FS_sort_by_name_down: 1;

Sort by name descending.


FS_sort_by_name_up

ts
readonly static FS_sort_by_name_up: 0;

Sort by name ascending.


FS_sort_by_size_down

ts
readonly static FS_sort_by_size_down: 3;

Sort by size descending.


FS_sort_by_size_up

ts
readonly static FS_sort_by_size_up: 2;

Sort by size ascending.


FSType_Any

ts
readonly static FSType_Any: 3;

Search virtual and external files.

Since

OpenXRay 2014-11-02, 827c9f58


FSType_External

ts
readonly static FSType_External: 2;

Search external files only.

Since

OpenXRay 2014-11-02, 827c9f58


FSType_Virtual

ts
readonly static FSType_Virtual: 1;

Search virtual registered files only.

Since

OpenXRay 2014-11-02, 827c9f58