cordova s​​tore fileEntry name to string

时间:2015-05-06 01:55:55

标签: javascript cordova cordova-plugins

我想使用writeLog将directoryEntry名称存储到文本文件中。但它似乎无法编写DOMString类型(directoryEntry.name的数据类型)。

这是我的代码

    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);
    });
});

上面代码的结果

App started, path/ [Wed May 06 2015 08:24:37 GMT+007 (WIB)]
如果有人能提供帮助,我们会很高兴。谢谢

original code

1 个答案:

答案 0 :(得分:0)

试试这个

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);
         }
      }
    }
}