Skip to content

Filesystem

This section contains documentation of functions and properties that allow you to check the existance of / delete a file, create / enumerate directories, and in other ways interact with and/or manipulate the filesystem.

If you wish to specifically read and write files, you should look at the file datastream class.

Functions

directory_create

Creates a directory if it doesn't already exist.

bool directory_create(string directory);

Arguments:

Returns:

true if the directory was successfully created or already exists, false otherwise.

Example:

void main() {
	if (directory_exists("test")) {
		alert("Info", "The test directory already exists; nothing to do");
		exit();
	}
	if (directory_create("test")) {
		alert("Info", "Directory created. Deleting...");
		alert("Info", directory_delete("test") ? "Success": "Fail");
	}
	else
		alert("Error", "Couldn't create the directory.");
}

directory_delete

Deletes a directory.

bool directory_delete(string directory);

Arguments:

Returns:

bool: true if the directory was successfully deleted, false otherwise.

directory_exists

Determine if a directory exists or not.

bool directory_exists(string directory);

Arguments:

Returns:

true if the directory exists, false otherwise.

Example:

void main() {
	alert("Directory exists", directory_exists("test") ? "There is a test folder in the current directory" : "There is not a test folder in the current directory");
}

file_copy

Coppies a file from one location to another.

bool file_copy(string source_filename, string destination_filename);

Arguments:

Returns:

bool: true if the file was successfully coppied, false otherwise.

file_delete

Deletes a file.

bool file_delete(string filename);

Arguments:

Returns:

bool: true if the file was successfully deleted, false otherwise.

file_exists

Check for the existence of a particular file.

bool file_exists(string file_path);

Arguments:

Returns:

bool: true if the file exists, false otherwise.

file_get_date_created

Get a datetime object representing the creation date of a particular file.

datetime file_get_date_created(string filename);

Arguments:

Returns:

datetime: an initialized datetime object, with all its fields set to the creation date of the file.

Remarks:

The date returned is in UTC, not your local timezone.

Example:

void main() {
	datetime dt = file_get_date_created("file_get_date_created.nvgt");
	alert("file_get_date_created.nvgt was created on", dt.year + "-" + dt.month + "-" + dt.day + ", " + dt.hour +":" + dt.minute + ":" + dt.second);
}

file_get_date_modified

Get a datetime object representing the modification date of a particular file.

datetime file_get_date_modified(string filename);

Arguments:

Returns:

datetime: an initialized datetime object, with all its fields set to the modification date of the file.

Remarks:

The date returned is in UTC, not your local timezone.

Example:

void main() {
	datetime dt = file_get_date_modified("file_get_date_modified.nvgt");
	alert("file_get_date_modified.nvgt was modified on", dt.year + "-" + dt.month + "-" + dt.day + ", " + dt.hour +":" + dt.minute + ":" + dt.second);
}

file_get_size

Get the size of a file (in bytes).

int64 file_get_size(string filename);

Arguments:

Returns:

int64: the size of the file (in bytes).

Example:

void main() {
	alert("file_get.size.nvgt is", file_get_size("file_get_size.nvgt") + " bytes");
}

glob

Return a list of files and directories on the filesystem given a path glob.

string[]@ glob(string path_pattern, glob_options options = GLOB_DEFAULT);

Arguments:

Returns:

string[]@: A list of all matching files and directories that match the given path pattern, an empty array on no matches or failure.

Remarks:

This function provides for one of the easiest ways to enumerate the filesystem in NVGT, particularly because the path patterns provided can actually cause semi-recursive directory searches. The search starts at the current working directory unless an absolute path is given.

The glob patterns have simple rules:

There is no guarantee that the items returned will appear in any particular order in the array.

The following glob_options constance are defined:

Example:

void main() {
	// List all .nvgt files within the filesystem documentation directory.
	string[]@ items = glob("../*/*.nvgt");
	alert("files found", string(items));
}

Global Properties

DIRECTORY_APPDATA

Property that returns the user's roaming application directory, which is usually where game data can be written to.

const string DIRECTORY_APPDATA;

remarks:

A slash character is already appended to the directory returned by this property.

This function may return different values depending on the operating system the application is being run on.

In any case, the directory returned should be writable.

Example:

void main() {
	alert("example", "data for the game could be stored at " + DIRECTORY_APPDATA + "my_game/");
}