Functions
basename | I Retrieves the base name of the file from the provided location, which is the last element of the path. |
copy | I Copy the file/directory in the old path to the new path. |
create | I Creates a file in the specified file path. |
createDir | I Creates a new directory with the specified name. |
createTemp | I Creates a temporary file. |
createTempDir | I Creates a temporary directory. |
getAbsolutePath | I Retrieves the absolute path from the provided location. |
getCurrentDir | I Returns the current working directory. |
getMetaData | I Returns the metadata information of the file specified in the file path. |
isAbsolutePath | I Reports whether the path is absolute. |
joinPath | I Joins any number of path elements into a single path. |
normalizePath | I Normalizes a path value. |
parentPath | I Returns the enclosing parent directory. |
readDir | I Reads the directory and returns a list of metadata of files and directories inside the specified directory. |
relativePath | I Returns a relative path, which is logically equivalent to the target path when joined to the base path with an intervening separator. |
remove | I Removes the specified file or directory. |
rename | I Renames(Moves) the old path with the new path. |
splitPath | I Splits a list of paths joined by the OS-specific path separator. |
test | I Tests a file path against a test condition . |
basename
Retrieves the base name of the file from the provided location, which is the last element of the path. Trailing path separators are removed before extracting the last element.
1 string name = check file:basename("/A/B/C.txt");
Parameters
- path string
String value of file path
copy
function copy(string sourcePath, string destinationPath, CopyOption... options) returns Error?
Copy the file/directory in the old path to the new path.
1check file:copy("/A/B/C", "/A/B/D", true);
Parameters
- sourcePath string
String value of the old file path
- destinationPath string
String value of the new file path
- options CopyOption...
Parameter to denote how the copy operation should be done. Supported options are,
REPLACE_EXISTING
- Replace the target path if it already exists,
COPY_ATTRIBUTES
- Copy the file attributes as well to the target,
NO_FOLLOW_LINKS
- If source is a symlink, only the link is copied, not the target of the link.
create
Creates a file in the specified file path. Truncates if the file already exists in the given path.
1check file:create("bar.txt");
Parameters
- path string
String value of the file path
createDir
Creates a new directory with the specified name.
1check file:createDir("foo/bar");
createTemp
Creates a temporary file.
1string tmpFile = check file:createTemp();
createTempDir
Creates a temporary directory.
1string tmpDir = check file:createTempDir();
getAbsolutePath
Retrieves the absolute path from the provided location.
1 string absolutePath = check file:getAbsolutePath(<@untainted> "test.txt");
Parameters
- path string
String value of the file path free from potential malicious codes
getCurrentDir
function getCurrentDir() returns string
Returns the current working directory.
1string dirPath = file:getCurrentDir();
Return Type
(string)Current working directory or else an empty string if the current working directory cannot be determined
getMetaData
Returns the metadata information of the file specified in the file path.
1file:MetaData result = check file:getMetaData("foo/bar.txt");
Parameters
- path string
String value of the file path.
isAbsolutePath
Reports whether the path is absolute. A path is absolute if it is independent of the current directory. On Unix, a path is absolute if it starts with the root. On Windows, a path is absolute if it has a prefix and starts with the root: c:\windows.
1 boolean isAbsolute = check file:isAbsolutePath("/A/B/C");
Parameters
- path string
String value of the file path
joinPath
Joins any number of path elements into a single path.
1 string path = check file:joinPath("/", "foo", "bar");
Parameters
- parts string...
String values of the file path parts
normalizePath
function normalizePath(string path, NormOption option) returns string | Error
Normalizes a path value.
1 string normalizedPath = check file:normalizePath("foo/../bar", file:CLEAN);
Parameters
- path string
String value of the file path
- option NormOption
Normalization option. Supported options are,
CLEAN
- Get the shortest path name equivalent to the given path by eliminating multiple separators, '.', and '..',
SYMLINK
- Evaluate a symlink,
NORMCASE
- Normalize the case of a pathname. On windows, all the characters are converted to lowercase and "/" is
converted to "\".
parentPath
Returns the enclosing parent directory. If the path is empty, parent returns ".". The returned path does not end in a separator unless it is the root directory.
1 string parentPath = check file:parentPath("/A/B/C.txt");
Parameters
- path string
String value of the file/directory path
readDir
Reads the directory and returns a list of metadata of files and directories inside the specified directory.
1file:MetaData[] results = check file:readDir("foo/bar");
Parameters
- path string
String value of the directory path.
relativePath
Returns a relative path, which is logically equivalent to the target path when joined to the base path with an intervening separator. An error is returned if the target path cannot be made relative to the base path.
1 string relative = check file:relativePath("a/b/e", "a/c/d");
remove
Removes the specified file or directory.
1check file:remove("foo/bar.txt");
rename
Renames(Moves) the old path with the new path. If the new path already exists and it is not a directory, this replaces the file.
1check file:rename("/A/B/C", "/A/B/D");
splitPath
Splits a list of paths joined by the OS-specific path separator.
1 string[] parts = check file:splitPath("/A/B/C");
Parameters
- path string
String value of the file path
test
function test(string path, TestOption testOption) returns boolean | Error
Tests a file path against a test condition .
1boolean result = check file:test("foo/bar.txt", file:EXISTS);
Parameters
- path string
String value of the file path
- testOption TestOption
The option to be tested upon the path. Supported options are,
EXISTS
- Test whether a file path exists,
IS_DIR
- Test whether a file path is a directory,
IS_SYMLINK
- Test whether a file path is a symlink,
READABLE
- Test whether a file path is readable,
WRITABLE
- Test whether a file path is writable.