Skip to main content

Check if a file or directory exists (file.exists)

Declaration

exists = file.exists(path)

Parameters

  • path
    String. Absolute file or directory path.

Returns

  • exists
    false if the path does not exist.
    "file" if the path is a file.
    "directory" if the path is a directory.

Notes

Determine whether a path is a file, a directory, or does not exist.

Example

if file.exists("/var/mobile/1.zip") then
sys.alert("/var/mobile/1.zip exists")
else
sys.alert("/var/mobile/1.zip does not exist")
end
--
if file.exists("/var/mobile/1.zip")=="file" then
sys.alert("/var/mobile/1.zip exists and is a file")
else
sys.alert("/var/mobile/1.zip is not a file")
end
--
if file.exists("/var/mobile/123/")=="directory" then
sys.alert("/var/mobile/123/ exists and is a directory")
else
sys.alert("/var/mobile/123/ is not a directory")
end

Note: Uses sys.alert