local io = require "io" local table = require "table" local string = require "string" module "file" -- file exists ------------------------ function exists(filename) local f = io.open(filename, "r") if f==nil then return false else f:close() return true end end -- file saver ------------------------- function save(filename, rbuf) if rbuf==nil then return false end local f = io.open(filename, "w+b") if f==nil then return false end f:write(rbuf) f:flush() f:close() return true end -- file loader ------------------------ function load(filename) local f = io.open(filename, "r") if f==nil then return nil end local cmdbuf = f:read("*all") f:close() return(cmdbuf) end function loadastable(filename) local f = io.open(filename, "r") if f==nil then return nil end local cmdbuf = {} while true do local line = f:read("*l") if line == nil then break end table.insert(cmdbuf,line) end f:close() return cmdbuf, table.getn(cmdbuf) end -- file extension --------------------- function getext(filename) local file_ext = nil for w in string.gfind(filename,"(%.%a*)") do file_ext = string.lower(string.sub(w,2,10)) end return file_ext end -- file name --------------------- function getname(filename) local file_name = nil for w in string.gfind(filename,"(%w*%.%w*)") do file_name = string.lower(string.sub(w,1,string.find(w,"%.")-1)) end return file_name end