---
title: FileSystemDirectoryEntry
slug: Web/API/FileSystemDirectoryEntry
translation_of: Web/API/FileSystemDirectoryEntry
---
<p>{{APIRef("File System API")}}{{Non-standard_header}}</p>

<p><a href="/en-US/docs/Web/API/File_and_Directory_Entries_API">文件和目录条目 API</a> 的 <strong><code>FileSystemDirectoryEntry</code></strong> 接口表示文件系统中的目录。它提供了方法,使其能够访问和操作目录中的文件,以及访问目录中的条目。</p>

<div class="note">
<p>由于这是个非标准的 API,它的规范当前并没有在标准进程中,重要的是要记住,并不是所有浏览器都实现了他,并且实现它的浏览器可能仅仅实现了一小部分。更多细节请查看 {{anch("Browser compatibility")}} 。</p>
</div>

<h2 id="basic_concepts" name="basic_concepts">基本概念</h2>

<p>你可以通过调用 {{domxref("FileSystemDirectoryEntry.getDirectory", "getDirectory()")}} 创建新的目录。如果你打算创建子目录,按需创建每个子目录。如果你尝试使用完整路径创建目录,包含不存在的父目录,会返回错误。所以需要在创建父目录之后,递归添加新的路径来创建层次。</p>

<h3 id="example" name="example">示例</h3>

<p>下面的代码中,我们创建了一个叫做 "Documents" 的目录。</p>

<pre class="brush: js">// Taking care of the browser-specific prefixes.
window.requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;
window.directoryEntry = window.directoryEntry || window.webkitDirectoryEntry;

...

function onFs(fs){
  fs.root.getDirectory('Documents', {create:true}, function(directoryEntry){
    //directoryEntry.isFile === false
    //directoryEntry.isDirectory === true
    //directoryEntry.name === 'Documents'
    //directoryEntry.fullPath === '/Documents'

    }, onError);

  }

// Opening a file system with temporary storage
window.requestFileSystem(TEMPORARY, 1024*1024 /*1MB*/, onFs, onError);</pre>

<h2 id="属性">属性</h2>

<p>这个接口没有自己的属性,但是从它的父接口 {{domxref("FileSystemEntry")}} 继承了属性。</p>

<h2 id="方法">方法</h2>

<p>这个接口从它的父接口 {{domxref("FileSystemEntry")}} 继承了方法。</p>

<dl>
 <dt>{{domxref("FileSystemDirectoryEntry.createReader", "createReader()")}}</dt>
 <dd>创建 {{domxref("FileSystemDirectoryReader")}} 对象,它可以用于服务目录中的条目。</dd>
 <dt>{{domxref("FileSystemDirectoryEntry.getDirectory", "getDirectory()")}}</dt>
 <dd>返回 {{domxref("FileSystemDirectoryEntry")}} 对象,表示位于给定路径的目录,相对于方法调用处的目录。</dd>
 <dt>{{domxref("FileSystemDirectoryEntry.getFile", "getFile()")}}</dt>
 <dd>返回 {{domxref("FileSystemFileEntry")}}对象,表示在目录层次中的一个文件,提供相对于方法调用处目录的路径。 </dd>
</dl>

<h3 id="废弃的方法">废弃的方法</h3>

<dl>
 <dt>{{domxref("FileSystemDirectoryEntry.removeRecursively", "removeRecursively()")}}</dt>
 <dd>删除目录和所有内容,包含子目录的内容。它已经从规范中移除。</dd>
</dl>

<h2 id="规范">规范</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('File System API')}}</td>
   <td>{{Spec2('File System API')}}</td>
   <td>Draft of proposed API</td>
  </tr>
 </tbody>
</table>

<p>这个 API 没有官方的  W3C 或者 WHATWG 规范。</p>

<h2 id="Browser_compatibility" name="Browser_compatibility">浏览器兼容性</h2>

<p>{{ CompatibilityTable }}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Edge</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Microsoft Edge</th>
   <th>Opera</th>
   <th>Safari (WebKit)</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>13 {{ property_prefix("webkit") }}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{ CompatGeckoDesktop(50) }}<sup>[2]</sup></td>
   <td>{{ CompatNo }}</td>
   <td>{{CompatNo}}<sup>[3]</sup></td>
   <td>{{ CompatNo }}</td>
   <td>{{ CompatNo }}</td>
  </tr>
  <tr>
   <td><code>removeRecursively()</code></td>
   <td>13 {{ property_prefix("webkit") }}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{ CompatNo }}<sup>[1]</sup></td>
   <td>{{ CompatNo }}</td>
   <td>{{ CompatNo }}</td>
   <td>{{ CompatNo }}</td>
   <td>{{ CompatNo }}</td>
  </tr>
  <tr>
   <td><code>getFile()</code> and <code>getDirectory()</code></td>
   <td>13 {{ property_prefix("webkit") }}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{ CompatGeckoDesktop(50) }}<sup>[2]</sup></td>
   <td>{{ CompatNo }}</td>
   <td>{{ CompatNo }}</td>
   <td>{{ CompatNo }}</td>
   <td>{{ CompatNo }}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Chrome for Android</th>
   <th>Edge</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Phone</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{ CompatNo }}</td>
   <td>0.16 {{ property_prefix("webkit") }}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{ CompatGeckoDesktop(50) }}<sup>[2]</sup></td>
   <td>{{ CompatNo }}</td>
   <td>{{ CompatNo }}</td>
   <td>{{ CompatNo }}</td>
  </tr>
  <tr>
   <td><code>removeRecursively()</code></td>
   <td>{{ CompatNo }}</td>
   <td>0.16 {{ property_prefix("webkit") }}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{ CompatNo }}<sup>[1]</sup></td>
   <td>{{ CompatNo }}</td>
   <td>{{ CompatNo }}</td>
   <td>{{ CompatNo }}</td>
  </tr>
  <tr>
   <td><code>getFile()</code> and <code>getDirectory()</code></td>
   <td>{{ CompatNo }}</td>
   <td>0.16 {{ property_prefix("webkit") }}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{ CompatGeckoDesktop(50) }}<sup>[2]</sup></td>
   <td>{{ CompatNo }}</td>
   <td>{{ CompatNo }}</td>
   <td>{{ CompatNo }}</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] 虽然 {{domxref("FileSystemDirectoryEntry.removeRecursively", "removeRecursively()")}} 方法存在于 Firefox 50,它所做的所有事情就是使用 <code>NS_ERROR_DOM_SECURITY_ERR</code> 调用错误回调。它已经从 Firefox 52 中移除了,并且也从规范中移除。</p>

<p>[2] 在 Firefox 中,错误回调的参数是 {{domxref("DOMException")}} ,而不是 {{domxref("FileError")}} 对象。</p>

<p>[3] Microsoft Edge 在 <code>WebKitEntry</code> 接口中实现了这个接口的功能,它就是 {{domxref("FileSystemEntry")}}。</p>

<h2 id="另见">另见</h2>

<ul>
 <li><a href="/en-US/docs/Web/API/File_and_Directory_Entries_API">文件和目录条目 API</a></li>
 <li><a href="/en-US/docs/Web/API/File_and_Directory_Entries_API/Introduction">文件系统 API 简介</a></li>
 <li>{{domxref("FileSystemDirectoryReader")}}</li>
 <li>{{domxref("FileSystemEntry")}}</li>
 <li>{{domxref("FileSystemFileEntry")}}</li>
</ul>