lua-users home
lua-l archive

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


On Thu, Sep 23, 2004 at 05:56:53AM +0400, Alexey Tourbin wrote:
> > 	function exists(n)
> > 		local f=io.open(n)
> > 		io.close(f)
> > 		return f==nil
> > 	end

function exists(fname)
        local f = io.open(fname, "r")
        if (f and f:read()) then return true end
end

> $ lua -e 'print(io.open("/etc"))'
> file (0x804f968)
> $

$ lua -lexists -e 'print(exists("/etc"))'

$ lua -lexists -e 'print(exists("/etc/passwd"))'
true
$