PtokaX forum

Archive => Archived 5.0 boards => Help with scripts => Topic started by: st0ne-db on 19 July, 2005, 00:32:17

Title: test to see if file exists
Post by: st0ne-db on 19 July, 2005, 00:32:17
i am using CodeBoard V2... i have a small problem with it.
the function in question is:

--- Utility function ..
function ReadIt(file)
 local msg = "\n"
 if (io.input(file)) then
    text = io.input(file)
    for line in text:lines() do
    msg = msg..line.."\n" end
    text:close()
    return msg
 else
    return "Please check the NFO name ["..file.."] does not exist.""
 end
end

i believe this statement is trying to see if the file is there
--if (io.input(file)) then
--  --if file exists.....[code]
--else
--return "Please check the NFO name ["..file.."] does...

but when a call is made to a file that is not present the script errors...

NFOPost.lua:178: bad argument #1 to `input' (NFOPosts/4.txt: No such file or directory

can someone please help?

Title:
Post by: st0ne-db on 19 July, 2005, 01:27:45
the code you posted worked perfectly. thank you for your prompt response.