This page has been translated automatically.
UnigineScript
The Language
Engine Library
Node-Related Classes
GUI-Related Classes
Plugins Library
High-Level Systems
Samples
Usage Examples
C++ API
API Reference
Integration Samples
Usage Examples
C++ Plugins
Migration
Migrating to UNIGINE 2.0
C++ API Migration
Migrating from UNIGINE 2.0 to UNIGINE 2.1
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

File System Functions

Variable absname (string path, string str)

Converts a relative filename and returns an absolute name. No attempt is made to create the shortest absolute name.

Arguments

  • string path - Current path.
  • string str - Relative path to be added.

Return value

Resulting path.

string basename (string path)

Returns a file name component of path. On Windows, both slash (/) and backslash (\) are used as directory separator character. In other environments, it is the forward slash (/).

Arguments

  • string path - Full path.

Return value

File name.

int chdir (string name)

Changes the current directory to a new one.

Arguments

  • string name - An absolute path to a new directory.

Return value

1 if the directory was changed; otherwise, 0.

Variable copy (string name, string new_name)

Copies one file into another one.
Notice
You must specify the full path to the file. To get the path to the data directory, use the engine.getDataPath() function.

Arguments

  • string name - Full path to the file to be copied.
  • string new_name - Full path to the new file.

Return value

1 if the file is copied successfully; otherwise, 0.

Examples

Source code (UnigineScript)
string src = engine.getDataPath() + "test.node"; // path to the file to be copied
string dest = engine.getDataPath() + "test/test_1.node"; // path to the destination file

log.message("%s\n",copy(src,dest));	// copy test.node into test/test_1.node
Output
int: 1
The test_1.node file is created automatically.
Notice
The test folder won't be created automatically. You should create it manually.

string dirname (string path)

Returns directory name component of given path. On Windows, both slash (/) and backslash (\) are used as directory separator character. In other environments, it is the forward slash (/).

Arguments

  • string path - Full path.

Return value

Directory name.

int get_mtime (string path)

Returns the time of the last modification of a given file or directory.
Notice
This function is a wrapper for a system-level function, thus an absolute path is required. engine.getDataPath() can be used to prepend the full path.
To change the current time stamp, use the set_mtime() function.

Arguments

  • string path - An absolute path to a file or a directory.

Return value

Time stamp of the last modification. If an error occurs, -1.

Examples

Source code (UnigineScript)
// concatenate the full path to the data directory and the relative path to the file to get the absolute path
string name = engine.getDataPath() + "samples/objects/billboards_00.cpp";
// print the current time stamp
log.message("get_mtime() returned: %d\n",get_mtime(name));
Output
get_mtime() returned: 1404355535

Variable is_absolute (string name)

Returns the value indicating whether the given path is absolute or not.

Arguments

  • string name - Path to a file.

Return value

1 if the given path is absolute; otherwise, 0.

Examples

  • On Windows:
    Source code (UnigineScript)
    is_absolute("C:\\Users\\my_user\\"); // return value = 1
    is_absolute("\\\\STUDIO\\soft\\windows\\Win7.iso"); // return value = 1
    is_absolute("..\\lib\\x64"); // return value = 0
    is_absolute("logs\\log.html"); // return value = 0
  • On Linux and Mac OS:
    Source code (UnigineScript)
    is_absolute("/home/my_user"); // return value = 1
    is_absolute("log.html"); // return value = 0

int is_dir (string path)

Checks if a given file system object exists and is actually a directory.
Notice
This function is a wraper for a system-level function, thus an absolute path is required. engine.getDataPath() can be used to prepend the full path.

Arguments

  • string path - An absolute path to a directory to check.

Return value

1 if the directory exists; otherwise, 0.

int is_file (string path)

Checks if a given file system object exists and is actually a file.
Notice
This function is a wraper for a system-level function, thus an absolute path is required. engine.getDataPath() can be used to prepend the full path.

Arguments

  • string path - An absolute path to a file to check.

Return value

1 if the file exists; otherwise, 0.

Variable is_hidden (string name)

Checks if the given file or directory is hidden or not.

Arguments

  • string name - An absolute path to the file or directory.

Return value

1 if the hidden attribute is set (i.e. the file or directory is hidden); otherwise, 0.

int mkdir (string pathname, int recursion = 0)

Attempts to create a directory named pathname, optionally with subdirectories if a recursion flag is set (for example, a/b/c/d). By default, only one directory is created.
Notice
This function is a wrapper for a system-level function, thus an absolute path is required. engine.getDataPath() can be used to prepend the full path.

Arguments

  • string pathname - An absolute path to the created directory.
  • int recursion - This is an optional argument. 1 to create subdirectories; 0 to create one.

Return value

Return one on success, or zero if an error occurred.

string pathname (string path)

Resolves references to '/./', '/../' and extra '/' characters in the input path and return the canonical absolute pathname. The resulting path will have no '/./' or '/../' components.

Arguments

  • string path - Input path.

Return value

Canonical pathname.

string relname (string path, string file)

Returns a relative path to a given file.

Arguments

  • string path - A path to be used as a reference point.
  • string file - A target file name.

Return value

Relative (to path location) path to the given file file.

int remove (string pathname)

Deletes a specified pathname from the filesystem.
Notice
This function is a wraper for a system-level function, thus an absolute path is required. engine.getDataPath() can be used to prepend the full path.

Arguments

  • string pathname - An absolute path name.

Return value

Return one on success, or zero if an error occurred.

int rename (string oldpath, string newpath)

Renames a file and moves it between directories, if required.
Notice
This function is a wrapper for a system-level function, thus an absolute path is required. engine.getDataPath() can be used to prepend the full path.

Arguments

  • string oldpath - An old absolute path name.
  • string newpath - A new absolute path name.

Return value

Return one on success, or zero if an error occurred.

int rmdir (string path, int recursion = 0)

Attempts to remove a given directory, optionally with subdirectories if a recursion flag is set (for example, a/b/c/d). By default, only one directory is removed.
Notice
This function is a wrapper for a system-level function, thus an absolute path is required. engine.getDataPath() can be used to prepend the full path.

Arguments

  • string path - An absolute path to the target directory.
  • int recursion - This is an optional argument. 1 to remove subdirectories; 0 to remove one.

Return value

1 if the directory is removed successfully; otherwise, 0.

Variable set_hidden (string name, int hidden)

Sets the hidden attribute indicating if the given file or directory is hidden or not.

Arguments

  • string name - An absolute path to the file or directory.
  • int hidden - 1 to make the file or directory hidden; 0 to make them visible in the file listing.

Return value

1 if the hidden attribute is set successfully; otherwise, 0.

Variable set_mtime (string name, long time)

Sets the time of the last modification of a given file or directory.
Notice
You should specify an absolute path to a file or directory. The engine.getDataPath() function can be used to prepend the full path.
To get the current time stamp, use the get_mtime() function.

Arguments

  • string name - An absolute path to a file or a directory.
  • long time - Time stamp to set.

Return value

1 if the time stamp is set successfully; otherwise, 0.

Examples

Source code (UnigineScript)
// concatenate the full path to the data directory and the relative path to the file to get the absolute path
string name = engine.getDataPath() + "samples/objects/billboards_00.cpp";
// assign the current time stamp value to the variable
long time = get_mtime(name);
// print the updated time stamp of the test.cpp
log.message("set_mtime() return value: %d\n",set_mtime(name,10L));
// print the saved and current time stamps to compare
log.message("Saved time stamp: %d\nUpdated time stamp: %d\n",time,get_mtime(name));
Output
set_mtime() return value: 1
Saved time stamp: 1389034178
Updated time stamp: 10
Last update: 2017-07-03
Build: ()