Reading a directory

Discuss the company and its products.
lb96
Posts: 18
Joined: 11:32, 06 Jul 2015

Reading a directory

Postby lb96 » 20:06, 12 Jul 2015

Hi

I been putting together an app to record altitude to a file and then email the contents. This is working well however I'd like to add some functions to manage the log files e.g read, delete and email. To start with I'd like to just list the directory contents. I'm writing files to cordova.file.dataDirectory on IOS. I have had a hunt around on the net however I can't find an example that I can get working.

The Cordova 3 docs have the below example. However what I don't understand is how do I add the directory I want to list ie the application data directory. I'm new to Cordova however this example doesn't appear to be complete to me.

Any help would be appreciated.

function success(entries) {
var i;
for (i=0; i<entries.length; i++) {
console.log(entries[i].name);
}
}

function fail(error) {
alert("Failed to list directory contents: " + error.code);
}

// Get a directory reader
var directoryReader = dirEntry.createReader();

// Get a list of all the entries in the directory
directoryReader.readEntries(success,fail);


Regards
LB

lb96
Posts: 18
Joined: 11:32, 06 Jul 2015

Re: Reading a directory

Postby lb96 » 08:58, 13 Jul 2015

For anyone who is interested I finally find a solution that works. It has to be said the Cordova docs are a bit rubbish...

function listDirectory() {

window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function (dirEntry) {
var directoryReader = dirEntry.createReader();
directoryReader.readEntries(dirSuccess,dirFail);
});
}

function dirSuccess(entries) {
console.log("INFO: Listing entries");
var i;
for (i=0; i<entries.length; i++) {
console.log(entries[i].name);
}
}

function dirFail(error) {
console.log("Failed to list directory contents: " + error.code);
}

User avatar
micke
Posts: 256
Joined: 20:49, 18 Nov 2013

Re: Reading a directory

Postby micke » 16:06, 25 Jul 2015

Thanks for sharing your findings!
Best regards, Mikael


Return to “General discussion”

Who is online

Users browsing this forum: No registered users and 2 guests