Desenvolvi algumas funções para tratamento de arquivos fácilmente, não é como a do Colex, que por sinal, é mais completa, mas, já ajuda.
function File:Exists(filename) local file = io.open(filename, "r") if (file == nil) then return false else file:close() return true end end function File:Create(filename, content) if (content == nil) then return false end local file = io.open(filename, "w") if (file == nil) then return false end file:write(content) file:flush() file:close() return true end function File:Save(filename, content) if (content == nil) then return false end local file = io.open(filename, "w+b") if (file == nil) then return false end file:write(content) file:flush() file:close() return true end function File:Load(filename) local file = io.open(filename, "r") if (file == nil) then return nil end local load = file:read("*all") file:close() return (load) end function File:LoadAsTable(filename) local file = io.open(filename, "r") if (file == nil) then return nil end local load = {} while true do local line = file:read("*l") if (line == nil) then break end table.insert(load, line) end file:close() return load, table.getn(load) end function File:GetExtension(filename) local fileExt = nil for w in string.gfind(filename, "(%.%a*)") do fileExt = string.lower(string.sub(w, 2, 10)) end return fileExt end function File:GetName(filename) local rFileName = nil for w in string.gfind(filename,"(%w*%.%w*)") do rFileName = string.lower(string.sub(w, 1, string.find(w, "%.")-1)) end return rFileName end
Creio que o nome das funções se auto-explicam, mas se tiverem dúvidas, é só postarem.