HTML5 File System - How to read directories using directory reader?

前端 未结 1 734
后悔当初
后悔当初 2020-12-10 18:01

I loaded a directory using file input and webkitdirectory as mentioned below.




        
相关标签:
1条回答
  • 2020-12-10 18:51

    To read the content of a directory :

    fs.root.getDirectory('Documents', {}, function(dirEntry){
      var dirReader = dirEntry.createReader();
      dirReader.readEntries(function(entries) {
        for(var i = 0; i < entries.length; i++) {
          var entry = entries[i];
          if (entry.isDirectory){
            console.log('Directory: ' + entry.fullPath);
          }
          else if (entry.isFile){
            console.log('File: ' + entry.fullPath);
          }
        }
    
      }, errorHandler);
    }, errorHandler);
    

    In the code above, the isDirectory and isFile properties are used in order to obtain a different output for directories and files, respectively. Additionally, we use the fullPath property in order to get the full path of the entry, instead of its name only.

    From : http://net.tutsplus.com/tutorials/html-css-techniques/toying-with-the-html5-filesystem-api/

    0 讨论(0)
提交回复
热议问题