Re: Lua, testing whether a file exists...
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Lua, testing whether a file exists...
- From: Alexey Tourbin <at@...>
- Date: 2004年9月23日 06:48:49 +0400
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
$