Lua snippet: check file exists


Lua snippet: check file exists

function file_exists(name) 
	local f=io.open(name,"r") 
	if f~=nil then 
		f:close() 
		return true 
	else
		return false
	end
end

Example:

print(file_exists('/proc/loadavg')) --true

Online demo: here

Leave a Reply