lua-users home
lua-l archive

Re: How do I test for the existens of a file

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


On 2008年10月25日 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;

AltStyle によって変換されたページ (->オリジナル) /