Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List files inside www folder in PhoneGap

Tags:

ios

cordova

Is it possible to list the files inside the www PhoneGap folder? And recursively?

I need it because I would like to preload all the images inside it.

like image 324
Tyilo Avatar asked Nov 28 '11 15:11

Tyilo


2 Answers

The official documentation for working with files in phonegap can be rather hard to get started with.

Here's a working example of listing the files in a folder other than the root (in this case one called Downloads).

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
   fileSystem.root.getDirectory("Downloads", {
           create: true
       }, function(directory) {

        var directoryReader = directory.createReader();
        directoryReader.readEntries(function(entries) {
            var i;
            for (i=0; i<entries.length; i++) {
                log(entries[i].name);
            }
        }, function (error) {
            alert(error.code);
        });

       } );
}, function(error) {
   alert("can't even get the file system: " + error.code);
});

Note this will give you a directory in the writable area (Documents on iOS, sdcard on Android, so may not help that much).

like image 104
Ben Clayton Avatar answered Nov 15 '22 07:11

Ben Clayton


here's a PhoneGap app that does just that, even if written for BlackBerry, the jscript/html code is the same and should work in your iOS app as well.

Hope this helps

like image 30
Leon Avatar answered Nov 15 '22 08:11

Leon