Is it possible to uncompress a zip file to an existing sub folder with the zip plugin?
I want to extract the files from a zip file to a sub folder in the system.CachesDirectory.
The zip simply contains files that are not in folders.
When I extract the files to system.CachesDirectory it works fine.
When I set the dstBaseDirectory to the system.pathForFile for the subfolder, it either does nothing or causes the simulator to freeze on launch.
I also tried changing the current directory to the subfolder path and then setting the dstBsaeDirectory to the current directory with the same results.
here is my code. this function checks to see if the folder exists. if it does not, then the folder is created and the files are unzipped.
[lua]
– simple listener for uncompress function
engine_zip[“listen”] = function(event)
if(event.isError)then
print(“ERROR!”)
else
print("event.name: " … event.name)
print("event.type: " … event.type)
end
end
engine_zip[“unzip”] = function(fname, zfile) – name of folder we want to create, name of zip file to uncompress
– main cache path
local main_path = system.pathForFile("", system.CachesDirectory)
– sub folder path
local docs_path = system.pathForFile(fname, system.CachesDirectory)
– function that tries to change the main directory to the sub folder path and returns a value based on whether it was successful or not.
local fexist = engine_zip[“folder”](fname, system.CachesDirectory)
local new_folder_path
local success = lfs.chdir(main_path)
– uncompress options
local zipoptions = {
zipFile = zfile,
zipBaseDir = system.ResourceDirectory,
--dstBaseDir = system.CachesDirectory,
dstBaseDir = docs_path,
listener = engine_zip[“listen”]
}
– change dir to cache path
lfs.chdir(main_path)
--if the sub folder doesn’t exist, create it
if(fexist==0)then
print(“MAKE " … fname … " FOLDER”)
lfs.mkdir(fname)
new_folder_path = lfs.currentdir() … “/” … fname
– after folder is created, check again before unzipping files into directory
fexist = engine_zip[“folder”](fname, system.CachesDirectory)
success = lfs.chdir(docs_path)
– if the conditions are met, unzip.
if(fexist==1 and success) then
print(“UNZIP”)
zip.uncompress(zipoptions)
end
end
end
[/lua]