Get Properties of Files or Directories Functions
The following functions allow getting the properties of a file or a directory in a predefined folder of the current project directory. The file system location allowed to get properties is the folder shared\scripting of the current project. For example, [Installation Drive]:\[Installation Folder]\[Project Name]\shared\scripting.
Such functions can be run synchronously or asynchronously, and in the last case, it is necessary to provide a callback method that will be executed when the operation is completed.
fileGetPropertiesSync
The fileGetPropertiesSync
function allows getting the properties of the file or directory specified by <relativePath>
in the predefined folder.
fileGetProperties
The fileGetProperties
function allows getting asynchronously the properties of the file or directory specified by <relativePath>
in the predefined folder. Then it calls the <callback>
with the operation result.
Syntax
(Synchronous get properties)
var result = fileGetPropertiesSync(<relativePath>)
(Asynchronous get properties. The result is provided in the callback method.)
fileGetProperties(<relativePath>, <callback>
Parameters Usage
Parameter | Type | Default | Use | Annotation |
relativePath | String | - | Mandatory | Relative path of the file to access in the shared\scripting folder of the current project. |
callback | Function | - | Mandatory for asynchronous calls | Object that identifies the callback function invoked to provide the result of the operation. |
The callback function is declared as follows:
function fileGetPropertiesCallback(<getPropertiesResult>)
{
//... Do callback stuff here ...
}
Where <getPropertiesResult>
is the result object.
Result
The functions fileGetPropertiesSync
and fileGetPropertiesCallback
return the FileGetPropertiesResult object.
Error Handling
Errors can occur in case:
- The specified
<relativePath>
: - Is missing, null, empty or white space
- Is not a string
- Is invalid (such as, path containing a root directory, wrong absolute path, path outside of the predefined folder, path or file name containing invalid characters, files or directories that have too long path). Note that invalid characters and the path length depend on the operating system.
- The callback is missing, invalid, null, or empty (for asynchronous function only).
- The related error is logged only in the Trace Viewer.
Examples of Use
How to get and print the properties of a file in a shared/scripting subfolder
var result = fileGetPropertiesSync("MyDirectory\\myFile.txt")
console("Properties:\n{0}", result)
If the value of the property exists
is True, all the properties are printed, otherwise it means that the path has not been found so the value of the other properties is not meaningful.
If the file exists, the parent
path is relative to the shared\scripting folder (in this example, parent
is equal to "MyDirectory"
).
How to get and print (asynchronously) the property of a directory in the shared/scripting folder
fileGetProperties("MyDir", getPropertiesCallback)
function getPropertiesCallback(getPropertiesResult)
{
console(getPropertiesResult)
}
If the value of the property exists
is True, all the properties are printed, otherwise it means that the path has not been found so the value of the other properties is not meaningful.
If the directory exists, the parent
path is relative to the shared\scripting folder (in this example, parent
is empty).