os.exists
Check if the specified file or directory exists.
exists(filename)Examples
Check if a file or path exists.
javascript
function main() {
Log(`os.exists("./strategyConfig"):`, os.exists("./strategyConfig"))
// Output: os.exists("./strategyConfig"): true
Log(`os.exists("./strategyConfig/testData.txt"):`, os.exists("./strategyConfig/testData.txt"))
// Output: os.exists("./strategyConfig/testData.txt"): true
// Log(`os.exists("../strategyConfig"):`, os.exists("../strategyConfig")) // a path containing
// ".." throws: invalid path: path traversal not allowed
Log(`os.exists("test_1.txt"):`, os.exists("test_1.txt"))
// Output: os.exists("test_1.txt"): true
Log(`os.exists("test_2.txt"):`, os.exists("test_2.txt"))
// Output: os.exists("test_2.txt"): false
}Returns
| Type | Description |
bool | Returns true if the file or directory exists, otherwise returns false. |
Arguments
| Name | Type | Required | Description |
filename | string | Yes | The file or directory path to check. |
See Also