[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How do I test for the existens of a file
- From: "Jerome Vuarand" <jerome.vuarand@...>
- Date: Fri, 24 Oct 2008 16:25:04 +0200
2008/10/24 Robert Raschke <rtrlists@googlemail.com>:
> On Fri, Oct 24, 2008 at 2:20 PM, 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
>>
>> How do I do that?
>
> I use
>
> function file_exists(file_name)
> local file = io.open(file_name)
> if file then
> file:close()
> end
> return file ~= nil
> end
If you have access to LuaFileSystem [1] you can also use:
function file_exist(file_name)
return lfs.attributes(file_name, 'mode')~=nil
end
This may or may not be faster depending on your setup.
[1] http://www.keplerproject.org/luafilesystem/