I thought I had the correct syntax but it apparently not working.
I have the following:
<lua>
if string.char(getMudletHomeDir():byte()) == "/" then _sep = "/" else _sep = "\\" end
function load_fishing()
local fishing_location = getMudletHomeDir() .. _sep .. "fishing"
if not lfs.attributes(fishing_location) then
echo("Fishing is NOT there")
else
echo("Fising is there")
end
</lua>
How do you check to see if a file exists?
Re: How do you check to see if a file exists?
Anybody know how to do this correctly?
Re: How do you check to see if a file exists?
What's the error it's giving?
I would think an easy "if fishing_location then" check would suffice; if the file is there, it's true. If not, it's nil.
I would think an easy "if fishing_location then" check would suffice; if the file is there, it's true. If not, it's nil.
Re: How do you check to see if a file exists?
Well the file is there but I get a nil value back. So that isn't the correct syntax.
Re: How do you check to see if a file exists?
According to the documentation for LFS, you should be able to get an error message from attributes. Try...
Failing that, I'm afraid I've done all I can do. Haven't used LFS much, and never in Mudlet.
Re: How do you check to see if a file exists?
I found a way to do this, maybe it will help someone:
I am not a coder, so if it's a very bad way of doing it, feel free to yell at me.
Code: Select all
local is_file = io.open(my_path/my_file)
if is_file == nil then
GUI.Mine:echo("NOPE","white","b10")
else
GUI.Mine:echo("YAY","yellow","b10")
end