[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua, testing whether a file exists...
- From: "Ashwin Hirschi" <deery@...>
- Date: Thu, 23 Sep 2004 05:40:02 +0200
function exists(fname)
local f = io.open(fname, "r")
if (f and f:read()) then return true end
end
This is probably not what you want: it'll leave the file open till the next GC closes the handle...
If you're serious about checking for file/directory existence (and such), you'd do well to look into Luiz' posix library. You can find it here:
http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/
Among other things it'll give you functions like "access" and "stat". These are more functional and in all likelihood more efficient as well.
Ashwin.
--
no signature is a signature.