Skip to content

Instantly share code, notes, and snippets.

@elvenhope
Last active August 9, 2018 12:51
Show Gist options
  • Save elvenhope/3e36dc3c1ea690b9f7af2b3a5734c910 to your computer and use it in GitHub Desktop.
Save elvenhope/3e36dc3c1ea690b9f7af2b3a5734c910 to your computer and use it in GitHub Desktop.
function doesFileExist( fname)
local results = false
local filePath = system.pathForFile( fname, system.DocumentsDirectory )
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 = system.pathForFile( File, system.DocumentsDirectory )
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 = system.pathForFile( File, system.DocumentsDirectory )
local file, errorString = io.open( path, "r" )
local contents
if not file then
print( "File error: " .. errorString )
else
contents = file:read( "*n" )
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