Check if a file or directory exists.
file_exists(path)
path (string) - File or directory path to checkBoolean: true if the path exists, false otherwise
Check before reading:
if file_exists("config.json") then
config = parse_json(load("config.json"))
else
print("Config file not found")
end
Guard file operations:
if file_exists("output.txt") then
remove_file("output.txt")
end
save("output.txt", "new data")
Conditional processing:
for file in ["data1.txt", "data2.txt", "data3.txt"] do
if file_exists(file) then
content = load(file)
process(content)
end
end