diff --git a/builtin/common/misc_helpers.lua b/builtin/common/misc_helpers.lua index 29aa3e5c23..1a3c586a72 100644 --- a/builtin/common/misc_helpers.lua +++ b/builtin/common/misc_helpers.lua @@ -872,3 +872,9 @@ function core.parse_coordinates(x, y, z, relative_to) local rz = core.parse_relative_number(z, relative_to.z) return rx and ry and rz and { x = rx, y = ry, z = rz } end + +function core.file_exists(path) + local file = io.open(path, "r") + if file then file:close() return true end + return false +end diff --git a/doc/lua_api.md b/doc/lua_api.md index e78ee81164..aee3552b7a 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -4317,6 +4317,9 @@ Helper functions * `tool_capabilities`: Tool capabilities table of the item * `time_from_last_punch`: time in seconds since last punch action * `wear`: Amount of wear the item starts with (default: 0) +* `core.file_exists(path)` + * Returns true if a file exists + * Use if you only want to check if a file exists, don't use to check if you can open it (example: you can check if a schematic exists before loading it)