download whole folder

Hi,

I’ve been scanning the tutorials and this forum and I can’t find a solution that would answer this simple question… Is it possible to simply download a whole folder with multiple images to temporary / documents directory and delete it if/when need be, or do I need to download and later delete each image individually? Is there any plugin for this kind of thing?

I have managed to create a network request for a couple of images in a table, but this time there are simply to many images in a folder and I have a couple of folders.

thanks for your help

If you can get your folder on the server put into a .zip file, you can then download the zip file with a single network.request API call and then use the zip plugin to unpack it.

However, cleaning up will probably require you to use the LFS API’s and get a list of the files and delete them. 

Rob

Zip plugin looks to have event.response with listing of the files. I guess one could put those in a table  and then delete them:

local zip = require( "plugin.zip" ) local function zipListener( event )     if ( event.isError ) then         print( "Error!" )     else         print ( event["type"] )  --\> list         print( event.response )         --\> [1] = table: 0x618001466580 {         --\>     ratio: 98         --\>     size: 2188295440         --\>     file: space.jpg         --\> [2] = table: 0x618001466580 {         --\>     ratio: 98         --\>     size: 2188295440         --\>     file: space1.jpg     end end -- List all files from "test.zip" with additional file info local zipOptions = {     zipFile = "test.zip",     zipBaseDir = system.DocumentsDirectory,     listener = zipListener } zip.list( zipOptions )

but it seems to me this is an opportunity for a new plugin/module for someone who knows more than I do about all this.

I have also discovered  os.remove function and it states that it deletes a file or directory:

os.remove( file )

file (required)

String. String specifying the name of the file or directory to remove.

but if I name a directory containing files it’s not working - only works if the folder is empty, else I get the: Directory not empty in console.

for anyone out there lfs works for deleting a folder as Rob suggested:

local doc\_dir = system.DocumentsDirectory;  local doc\_path = system.pathForFile("myFolder", doc\_dir);  local resultOK, errorMsg;  for file in lfs.dir(doc\_path) do      local theFile = doc\_path.."/"..file;      if (lfs.attributes(theFile, "mode") ~= "directory") then          resultOK, errorMsg = os.remove(theFile);          if (resultOK) then              print(file.." removed");          else              print("Error removing file: "..file..":"..errorMsg);          end      end      --[[if you want to remove the folder itself after all the files have been deleted        os.remove( doc\_path )      ]]  end

If you can get your folder on the server put into a .zip file, you can then download the zip file with a single network.request API call and then use the zip plugin to unpack it.

However, cleaning up will probably require you to use the LFS API’s and get a list of the files and delete them. 

Rob

Zip plugin looks to have event.response with listing of the files. I guess one could put those in a table  and then delete them:

local zip = require( "plugin.zip" ) local function zipListener( event )     if ( event.isError ) then         print( "Error!" )     else         print ( event["type"] )  --\> list         print( event.response )         --\> [1] = table: 0x618001466580 {         --\>     ratio: 98         --\>     size: 2188295440         --\>     file: space.jpg         --\> [2] = table: 0x618001466580 {         --\>     ratio: 98         --\>     size: 2188295440         --\>     file: space1.jpg     end end -- List all files from "test.zip" with additional file info local zipOptions = {     zipFile = "test.zip",     zipBaseDir = system.DocumentsDirectory,     listener = zipListener } zip.list( zipOptions )

but it seems to me this is an opportunity for a new plugin/module for someone who knows more than I do about all this.

I have also discovered  os.remove function and it states that it deletes a file or directory:

os.remove( file )

file (required)

String. String specifying the name of the file or directory to remove.

but if I name a directory containing files it’s not working - only works if the folder is empty, else I get the: Directory not empty in console.

for anyone out there lfs works for deleting a folder as Rob suggested:

local doc\_dir = system.DocumentsDirectory;  local doc\_path = system.pathForFile("myFolder", doc\_dir);  local resultOK, errorMsg;  for file in lfs.dir(doc\_path) do      local theFile = doc\_path.."/"..file;      if (lfs.attributes(theFile, "mode") ~= "directory") then          resultOK, errorMsg = os.remove(theFile);          if (resultOK) then              print(file.." removed");          else              print("Error removing file: "..file..":"..errorMsg);          end      end      --[[if you want to remove the folder itself after all the files have been deleted        os.remove( doc\_path )      ]]  end