I have tried the following:
[lua]
function copyFile( srcName, srcPath, dstName, dstPath )
--copy the source file to the destination file
local rfilePath = system.pathForFile( srcName, srcPath )
local wfilePath = system.pathForFile( dstName, dstPath )
print (rfilePath )
print (wfilePath )
local rfh = io.open( rfilePath, “rb” )
local wfh = io.open( wfilePath, “wb” )
print (rfh)
if not ( wfh ) then
print( “writeFileName open error!” )
--return false
else
--read the file from ‘system.ResourceDirectory’ and write to the destination directory
local data = rfh:read( “*a” )
if not ( data ) then
print( “read error!” )
– return false
else
if not ( wfh:write( data ) ) then
print( “write error!” )
– return false
end
end
end
--clean up file handles
rfh:close()
wfh:close()
end
copyFile( “backgrass.txt”, nil, “backgrass.png”, system.DocumentsDirectory)
local catImage = display.newImage( “backgrass.png”, system.DocumentsDirectory, 0, 100 )
[/lua]
the ADB log states:
nil --this is the first print I use
/data/data/some app/app_data/backgrass.png – second print statement
Runtime error
bad argument #1 to ‘open’ (string expected, got nil) – this is the same nil as in my first print
stack traceback:
[C] : in function ‘open’
?: in function ‘copyFile’
?: in main chunk
as I can see it looks like the pathforfile module isn’t working as it should.
and the file backgrass.txt is obviously in my resourcefiles…all lowercase.