lua-users home
lua-l archive

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

> Please can someone tell me if Lua can tell if a file exists?

The only ANSI C way to do this is to open it:

	function exists(n)
		return f==nil

> I've tried testing for for a valid return from, but if the file doesn't exist, Lua throws up a default error, never mind trying to run my own handling code...

It works for me:

% lua
Lua 5.0  Copyright (C) 1994-2003 Tecgraf, PUC-Rio
> print("/etc/passwd")
file (0x80648b8)
> print("/etc/Passwd"); print"ok"
nil     /etc/Passwd: No such file or directory  2