NEED HELP: copyFile keeps returning error about nil ?!?!? STUMPED!

Hey all, I’ve been pulling my hair out!!!

When my app starts, I am attempting to copy a file from my resource directory to the system.DocumentsDirectory and when I try to run the app in the simulator, it throws the following error back:

attempt to call global ‘copyFile’ (a nil value)

stack traceback:

  [C]: in function ‘copyFile’

I’ve even tried making this the only line of code in my main.lua and it is still throwing back the above error:

copyFile( “data.txt”, system.ResourceDirectory, “data.txt”, system.DocumentsDirectory )

My directory for this project contains the following files, so I can confirm the file is there:

build.settings

config.lua

data.txt

main.lua

I’m going NUTS!  What am I missing here?  

So, i just tried the following code from the API docs and it is STILL throwing back the same error:


local path = system.pathForFile( “data.txt”, system.ResourceDirectory )

local file = io.open( path, “r” )

for line in file:lines() do

    print( line )

end

io.close( file )

file = nil


(string expected, got nil)  

Why Can’t I open/read/copy files from my Resource Directory?!?!?

So, what is the syntax for copying a file from my  resource directory to the documents directory???

This are two different errors. In the first post you are getting the error because LUA can not find the function copyFile. Make sure the copyFile function is in scope when you are calling it. The second error is more problematic check to see that you get valid values from the functions.

local path = system.pathForFile( "data.txt", system.ResourceDirectory ) if not path then print("Error pathForFile") return end local file = io.open( path, "r" ) if not file then print("Error io.open") return end for line in file:lines() do print( line ) end io.close( file ) file = nil

So, i just tried the following code from the API docs and it is STILL throwing back the same error:


local path = system.pathForFile( “data.txt”, system.ResourceDirectory )

local file = io.open( path, “r” )

for line in file:lines() do

    print( line )

end

io.close( file )

file = nil


(string expected, got nil)  

Why Can’t I open/read/copy files from my Resource Directory?!?!?

So, what is the syntax for copying a file from my  resource directory to the documents directory???

This are two different errors. In the first post you are getting the error because LUA can not find the function copyFile. Make sure the copyFile function is in scope when you are calling it. The second error is more problematic check to see that you get valid values from the functions.

local path = system.pathForFile( "data.txt", system.ResourceDirectory ) if not path then print("Error pathForFile") return end local file = io.open( path, "r" ) if not file then print("Error io.open") return end for line in file:lines() do print( line ) end io.close( file ) file = nil