lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Sat, 25 Oct 2008 16:06:05 -0700 (PDT)
TheLonelyStar <nabble2@lonely-star.org> wrote:

> I want to test if a specific file exist, and do something if yes. Like
> 
> if <file exist> then
>   <do something>
> else
>   <do something else>
> end
use lfs module (search at LuaForge), or write this:
local fl = io.open("file.to.test");
if fl then
  fl:close();
  <file exists; do not forget to close it first. or read data if that's
  what you need>
else
  print("no file. so sad.");
end;