Skip to content

Instantly share code, notes, and snippets.

@elvenhope
Created July 29, 2020 17:13
Show Gist options
  • Save elvenhope/04feba0902f8886d97c6086253b86276 to your computer and use it in GitHub Desktop.
Save elvenhope/04feba0902f8886d97c6086253b86276 to your computer and use it in GitHub Desktop.
function script_path()
local str = debug.getinfo(2, "S").source:sub(2)
return str:match("(.*/)")
end
function doesFileExist(fname)
local results = false
local filePath = script_path() .. "/" .. fname
if ( filePath ) then
local file, errorString = io.open( filePath, "r" )
if not file then
print( "File error: " .. errorString )
else
print( "File found: " .. fname )
results = true
file:close()
end
end
return results
end
function WriteFile(saveData,File)
local path = script_path() .. "/" .. File
local file, errorString = io.open( path, "w" )
if not file then
print( "File error: " .. errorString )
else
file:write( saveData )
io.close( file )
end
file = nil
end
function ReadFile(File)
local path = script_path() .. "/" .. File
local file, errorString = io.open( path, "r" )
local contents
if not file then
print( "File error: " .. errorString )
else
contents = file:read( "*a" )
io.close( file )
end
file = nil
return contents
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment