file_exists()

Check if a file or directory exists.

Signature

file_exists(path)

Parameters

Returns

Boolean: true if the path exists, false otherwise

Examples

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

See Also