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.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
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
int: 1
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.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 a file or a directory.
Return value
Time stamp of the last modification. If an error occurs, -1.Examples
// 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));
get_mtime() returned: 1404355535
int is_dir (string path)
Checks if a given file system object exists and is actually a directory.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.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.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.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.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.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.You should specify an absolute path to a file or directory. The engine.getDataPath() function can be used to prepend the full path.
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
// 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));
set_mtime() return value: 1
Saved time stamp: 1389034178
Updated time stamp: 10
Last update: 03.07.2017
Помогите сделать статью лучше
Была ли эта статья полезной?
(или выберите слово/фразу и нажмите Ctrl+Enter