这是 实验性技术
检查 浏览器兼容性表格 要小心谨慎在生产中使用这之前。

FileSystemDirectoryEntry 接口方法 createReader () 返回 FileSystemDirectoryReader object which can be used to read the entries in the directory.

句法

directoryReader = FileSystemDirectoryEntry.createReader();
					

参数

None.

返回值

A FileSystemDirectoryReader object which can be used to read the directory's entries.

范例

This example creates a method called readDirectory() , which fetches all of the entries in the specified FileSystemDirectoryEntry and returns them in an array.

function readDirectory(directory) {
  let dirReader = directory.createReader();
  let entries = [];
  let getEntries = function() {
    dirReader.readEntries(function(results) {
      if (results.length) {
        entries = entries.concat(toArray(results));
        getEntries();
      }
    }, function(error) {
      /* handle error -- error is a FileError object */
    });
  };
  getEntries();
  return entries;
}
					

This works by creating an internal function, getEntries() , which calls itself recursively to get all the entries in the directory, concatenating each batch to the array. Each iteration, readEntries() is called to get more entries. When it returns an empty array, the end of the directory has beenr reached, and the recursion ends. Once control is returned to readDirectory() , the array is returned to the caller.

规范

规范 状态 注释
文件和目录条目 API
The definition of 'createReader()' in that specification.
草案 最初的规范。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
createReader Chrome 13 Edge 79 Firefox 50 IE No Opera No Safari 11.1 WebView Android ≤37 Chrome Android 18 Firefox Android 50 Opera Android No Safari iOS 11.3 Samsung Internet Android Yes

图例

完整支持

完整支持

不支持

不支持

实验。期望将来行为有所改变。

实验。期望将来行为有所改变。

另请参阅

元数据

  • 最后修改: