isfile
Checks if a path points to a file.
Syntax
isfile(path: string) -> booleanParameters
| Parameter | Type | Description |
|---|---|---|
path | string | The path to check |
Returns
| Type | Description |
|---|---|
boolean | true if the path is a file |
Description
isfile returns whether the specified path exists and is a file (not a folder).
Example
writefile("test.txt", "Hello")
makefolder("testfolder")
print(isfile("test.txt")) -- true
print(isfile("testfolder")) -- false (it's a folder)
print(isfile("nonexistent")) -- false (doesn't exist)Safe File Reading
local function safeRead(path)
if isfile(path) then
return readfile(path)
end
return nil
end
local content = safeRead("config.json")
if content then
print("Config loaded")
else
print("Config not found")
end