问题
I want to store a directoryEntry name to a text file using writeLog. but it seems it cannot write DOMString type (data type of directoryEntry.name).
this is my code
window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory, function(dir) {
console.log("got main dir",dir);
dir.getFile("log.txt", {create:true}, function(file) {
console.log("got the file", file);
logOb = file;
var dirName = dir.name;
var dirPath = dir.fullPath;
writeLog("App started"+dirName+", path"+dirPath);
});
});
result of code above
App started, path/ [Wed May 06 2015 08:24:37 GMT+007 (WIB)]
would be glad if anyone can help. thank you
original code
回答1:
Try this
function getRootDirSuccess(dirEntry) {
// Get a directory reader
var directoryReader = dirEntry.createReader();
// Get a list of all the entries in the directory
directoryReader.readEntries(dirReadSuccess, myKnovel.page.fail);
}
function dirReadSuccess(entries) {
if (entries.length > 0) {
for (var i = 0; i < entries.length; i++) {
if (entries[i].isDirectory) {
console.log("it is a directory and the name is",entries[i].name);
} else {
console.log("it is not a directory and the name is",entries[i].name);
}
}
}
}
来源:https://stackoverflow.com/questions/30066175/cordova-store-fileentry-name-to-string