File Exists (code snippet)

Description

Check if a file exists.

Requires: None

Code

FileExists.fh_lua
-- Check if file exists
function FileExists(strFileName)
	local fileHandle = io.open(strFileName,"r")
	if fileHandle ~= nil then
		io.close(fileHandle)
		return true
	else
		return false
	end
end

Description

Check if a file exists using LUA File System library.

Requires: lfs

Code

FileExists.fh_lua
-- Check if file exists
function FileExists(strFileName)
	if lfs.attributes(strFileName,"mode") == "file" then
		return true
	else
		return false
	end
end