I can’t find any copy() function in API. Maybe doesn’t exist one.
For a text file, you could load it into a string and then write it to cache directoty. The same with html files.
Maybe it is possible to do the same with images but I’m not an expert with binary data.
[import]uid: 138389 topic_id: 30966 reply_id: 124169[/import]
Thanks. But I can’t even chdir on the “root” of the app !
How to copy file with the LFS library ?
[import]uid: 5578 topic_id: 30966 reply_id: 124170[/import]
Bump!
I would also need to know how to do this.
Thanks 
[import]uid: 80100 topic_id: 30966 reply_id: 124172[/import]
I’ve made some steps further into this problem.
After crawling from google into the corona labs.com website (yes, information is everywhere and nowhere here…), I have found that blog post http://www.coronalabs.com/blog/2012/05/23/faq-wednesday-6/ from T.Newman :
On Android, accessing the Resource directory is limited because it’s not a real directory, but files enclosed in a zip file. Corona allows directly loading images and audio files using audio and image APIs, but has limited access to Resource files using the file I/O APIs. For this reason you can’t use the new Lua File System (LFS) to access files in the Resource directory or any Resource subdirectory on Android. File and subdirectory access to the Document and Temporary directories on Android devices is possible.
This may end my search and make me going into a deadlock.
My iOS app copy a lot of html files and images files from the resource Directory to the cache folder. Then, a procedure update the content from the net (add, replace images and html) if needed.
This seems to be impossible in Android.
It seems I have to load images in memory and then write then on a Documents or Caches folder. And there’s nothing to do with html/txt files…
This kind of operations would be time consuming and also memory consuming.
I can’t believe there is no other way to do for a cross-platform SDK !!!
[import]uid: 5578 topic_id: 30966 reply_id: 124175[/import]
>>>It seems I have to load images in memory and then write then on a Documents or Caches folder. >>>And there’s nothing to do with html/txt files…
I thing you should put a “please wait …” text on first app start, you should load every text or html file from Resource directory in a string, then you should write to your cache or documents directory but I think in your case you could find another solution.
>>>My iOS app copy a lot of html files and images files from the resource Directory to the cache folder. >>>Then, a procedure update the content from the net (add, replace images and html) if needed.
How you did it on iOS? [import]uid: 138389 topic_id: 30966 reply_id: 124178[/import]
@Vovasoft Yes I know there’s nothing to do with html files, except I use the same procedure for any file.
I have more than a wait message : I have a visual loader to let the user see the app configuring itself.
On iOS I use system.pathForFile and system.Resources/CachesDirectory, and LFS lua library and io.* commands. All that stuff can not work on Android as the resources file do not exist and system.pathForFile works only after Documents and Caches directories have been created by the app.
To update, I use json file built from mySQL updates. Then I update the json, look for new files and updated files (with timestamps) and download what I need to a Caches directory.
[import]uid: 5578 topic_id: 30966 reply_id: 124183[/import]
@MagnoliaPower
>>>On iOS I use system.pathForFile and system.Resources/CachesDirectory, and LFS lua library and io.* commands.
PLEASE post here that piece of code.
I can’t understand what you can do on ios and not on Android. [import]uid: 138389 topic_id: 30966 reply_id: 124184[/import]
On Android, I can not open the resources directory (it does not exist, because the android app is a zip file). Then I can not copy/move files (images, html, txt, css, …) from the resources directory to a caches or tmp directory.
Corona can only load image and audio files into the memory of the android but can not access to the file to make some basic stuff such as copy, move, files wich is possible on iOS (my app works quite well on iOS and has been validated by Apple). [import]uid: 5578 topic_id: 30966 reply_id: 124186[/import]
>>>On Android, I can not open the resources directory (it does not exist, because the android app is a >>>zip file). Then I can not copy/move files (images, html, txt, css, …) from the resources directory to a >>>caches or tmp directory.
OK but how you did it on ios ?
Could you write it here. [import]uid: 138389 topic_id: 30966 reply_id: 124187[/import]
After a search on google, I have found that on coronalabs : http://developer.coronalabs.com/forum/2011/12/13/cant-find-file-ressoure-directory-only-android
This explanation / thread should be in the documentation !!!
[import]uid: 5578 topic_id: 30966 reply_id: 124188[/import]
I use something like that, from a tutorial found in this website :
Utils is a module.
message send back a message I can print out to the console for debuguing or on the user screen if needed.
[code]
utils.copyFile = function ( srcName, srcPath, dstName, dstPath, overwrite )
local message
local succes
local results = true – assume no errors
– Copy the source file to the destination file
local rfilePath = system.pathForFile( srcName, srcPath )
local wfilePath = system.pathForFile( dstName, dstPath )
local rfh = io.open( rfilePath, “rb” )
local wfh = io.open( wfilePath, “wb” )
if not wfh then
–print( “writeFileName open error!” )
results = false – error
else
– Read the file from the Resource directory and write it to the destination directory
local data = rfh:read( “*a” )
if not data then
–print( “read error!” )
results = false – error
else
if not wfh:write( data ) then
–print( “write error!” )
results = false – error
end
end
end
– Clean up our file handles
rfh:close()
wfh:close()
if results == true then
succes = “succeded”
else
success = “failed”
end
message = "copy “…tostring(srcName)…” "…tostring(succes)
return message
end
[/code] [import]uid: 5578 topic_id: 30966 reply_id: 124190[/import]
I have also this one to use subfolders :
[code]
utils.copyFileInFolder = function(fichier, cheminSource, destination, sousDossier, overwrite)
–print(tostring(fichier)…" “…tostring(cheminSource)…” “…tostring(destination)…” "…tostring(sousDossier))
lfs = require “lfs”
local results = true
local source_path = system.pathForFile(fichier, cheminSource)
local readFile = io.open(source_path, “rb”)
local data = readFile:read("*a")
local dest_path = system.pathForFile("", destination)
local success = lfs.chdir(dest_path)
local dest_folder = lfs.currentdir()…"/"…sousDossier…"/"
–print("DESTINATION : "…tostring(dest_folder))
local success = lfs.chdir(dest_folder)
local myFile = io.open( dest_folder…"/"…fichier, “w+b” )
myFile:write(data)
readFile:close()
myFile:close()
lfs.chdir(dest_path)
return "succes : “…tostring(fichier)…” copié vers "…tostring(dest_folder)
end
[/code] [import]uid: 5578 topic_id: 30966 reply_id: 124191[/import]
@MagnoliaPower,
I didn’t see it before.
Why you thing this code will not work on Android. Did you test it ? [import]uid: 138389 topic_id: 30966 reply_id: 124192[/import]