Last active
August 9, 2018 12:51
-
-
Save elvenhope/3e36dc3c1ea690b9f7af2b3a5734c910 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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