Type/to search
Built-in Functions
Global
Log
Market
Trade
Account
Futures
Exchange
IO
Network
Storage
Threads
TA
Talib
OS
os
os.open
os.fgets
os.fputs
os.mmap
os.getRootDir
os.listFiles
os.exists
os.remove
os.mkdir
os.rmdir
os.rename
os.stat
os.exit
File
ListFilesResult
FileStat
Structures
Built-in Variables and Constants
Conventions
Exchanges

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

TypeDescription

bool

Returns true if the file or directory exists, otherwise returns false.

Arguments

NameTypeRequiredDescription

filename

string

Yes

The file or directory path to check.

See Also