Folder Exists (code snippet)

Description

Checks if a folder exists.

Requires: None

Code

FolderExists.fh_lua
-- Check if folder exists --
function FolderExists(strFolderName)
	local fileHandle, strError = io.open(strFolderName.."\\*.*","r")
	if fileHandle ~= nil then
		io.close(fileHandle)
		return true
	else
		if string.match(strError,"No such file or directory") then
			return false
		else
			return true
		end
	end
end

Description

Check if a folder exists using LUA File System library.

Requires: lfs

Code

FolderExists.fh_lua
-- Check if folder exists --
function FolderExists(strFolderName)
	if lfs.attributes(strFolderName:gsub("\\$",""),"mode") == "directory" then
		return true
	else
		return false
	end
end