cordova store fileEntry name to string

偶尔善良 提交于 2019-12-25 16:54:56

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!