0

Is it possible to download a folder and its contents using air for android? I would like to also use the same code on iPhone.

I need it to be stored in the application storage so we can reference the content once downloaded.

I know it's possible to download content as referenced in this question: Download Content using Air For Android

but can a person download the entire folder and again store it in the application directory?

Thanks

@lukevain? :)

Community
  • 1
  • 1
Papa De Beau
  • 3,744
  • 18
  • 79
  • 137
  • I can imagine you can put all urls in a textfile on the server, download that and then download all individual files listed there. – zapl Aug 28 '12 at 00:31
  • Well there is a way I know it. It can be done with as3 I am sure. I think it has something to do with a loop. If I could only tell how to see if a file is a folder or not. Then I think I can do it – Papa De Beau Aug 28 '12 at 02:35

2 Answers2

0

Are you downloading this from a web server? If so this is not going to work and I would recommend using a php script to list all the files in the remote directory.

If this is local you can use this:

//using the application storage dir. This will work on iOS and Android
var f:File = File.applicationStorageDirectory.resolvePath("yourFolder/"); 
//you can also use getDirectoryListingAsync to have this run in the background
var filesList:Array = f.getDirectoryListing();
for (var i:int = 0; i < filesList.length; i++) {
    trace(filesList[i].nativePath);
}
francis
  • 5,889
  • 3
  • 27
  • 51
  • Yes, from a web server. I got it to work already for individual file. Here is the link: http://stackoverflow.com/questions/12033442/as3-android-saving-remote-sounds-on-sdcard-accessing-later – Papa De Beau Aug 28 '12 at 01:17
  • It doesn't look like you're downloading from a web server in that post. getDirectoryLisring will work in that case. – francis Aug 29 '12 at 01:45
  • Is it possible for flash download a folder and its contents or do I need to create a php script as you suggested to get the url paths to all contents? See this question if so: http://stackoverflow.com/questions/12233859/php-get-path-to-every-file-in-folder-subfolder-into-array – Papa De Beau Sep 02 '12 at 06:28
  • @PapaDeBeau not without using AIR – francis Sep 02 '12 at 07:17
0

This is not the answer of how to get contents of a folder from the server but it is a way to search through a folder of your choice on the local machine. It only goes 3 levels deep and it may not be the best way to find folders because it checks to see if their extension is null and I made it assume it is a folder. Then I search in that folder. Anyway here it is.

You will need do create a text field and give it an instance name of "daText";

Here is the code:

import flash.filesystem.*;
import flash.media.*;
var myFolder:String = "images/"; /// change this to the folder of your choice :)

var desktop:File = File.applicationDirectory.resolvePath(myFolder);
var files:Array = desktop.getDirectoryListing();
for (var i:uint = 0; i < files.length; i++)
{

    if (files[i].extension == null)
    {

        daText.text +=  files[i].name + "\n";
        var anotherArray:File = File.applicationDirectory.resolvePath(myFolder+files[i].name);
        var h:Array = anotherArray.getDirectoryListing();
        for (var a:uint = 0; a < h.length; a++)
        {
            daText.text +=  "----" + h[a].name + "\n";
            if (h[a].extension == null)
            {

                var oneMoreArray:File = File.applicationDirectory.resolvePath(myFolder+files[i].name+"/"+h[a].name+"/");
                var C:Array = oneMoreArray.getDirectoryListing();
                for (var B:uint = 0; B < C.length; B++)
                {
                    daText.text +=  "*******"+C[B].name + "\n";
                }
            }
        }
    }

}
Papa De Beau
  • 3,744
  • 18
  • 79
  • 137
  • I'm confused here. You're using the File class, this will not work to access files from a web server. – francis Aug 29 '12 at 01:44