lua-users home
lua-l archive

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



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.