Reputation: 30102
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.
Upvotes: 6
Views: 7001
Reputation: 82219
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).
Upvotes: 3
Reputation: 4532
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
Upvotes: 2