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
Reading a directory
Re: Reading a directory
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);
}
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);
}
Re: Reading a directory
Thanks for sharing your findings!
Best regards, Mikael
Best regards, Mikael
Return to “General discussion”
Who is online
Users browsing this forum: No registered users and 2 guests