Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1125129 of FileSystemDirectoryEntry

  • Revision slug: Web/API/FileSystemDirectoryEntry
  • Revision title: FileSystemDirectoryEntry
  • Revision id: 1125129
  • Created:
  • Creator: Sheppy
  • Is current revision? Yes
  • Comment Edge compat info

Revision Content

{{APIRef("File System API")}}{{Non-standard_header}}

The FileSystemDirectoryEntry interface of the File and Directory Entries API represents a directory in a file system. It provides methods which make it possible to access and manipulate the files in a directory, as well as to access the entries within the directory.

Because this is a non-standard API, whose specification is not currently on a standards track, it's important to keep in mind that not all browsers implement it, and those that do may implement only small portions of it. Check the {{anch("Browser compatibility")}} section for details.

Basic concepts

You can create a new directory by calling {{domxref("FileSystemDirectoryEntry.getDirectory", "getDirectory()")}}. If you want to create subdirectories, create each child directory in sequence. If you try creating a directory using a full path that includes parent directories that do not exist yet, an error is returned. So create the hierarchy by recursively adding a new path after creating the parent directory.

Example

In the following code snippet, we create a directory called "Documents."

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

Properties

This interface has no properties of its own, but inherits properties from its parent interface, {{domxref("FileSystemEntry")}}.

Methods

This interface inherits methods from its parent interface, {{domxref("FileSystemEntry")}}.

{{domxref("FileSystemDirectoryEntry.createReader", "createReader()")}}
Creates a {{domxref("FileSystemDirectoryReader")}} object which can be used to read the entries in this directory.
{{domxref("FileSystemDirectoryEntry.getDirectory", "getDirectory()")}}
Returns a {{domxref("FileSystemDirectoryEntry")}} object representing a directory located at a given path, relative to the directory on which the method is called.
{{domxref("FileSystemDirectoryEntry.getFile", "getFile()")}}
Returns a {{domxref("FileSystemFileEntry")}} object representing a file located within the directory's hierarchy, given a path relative to the directory on which the method is called.
{{domxref("FileSystemDirectoryEntry.removeRecursively", "removeRecursively()")}}
Deletes a directory and all of its contents, including the contents of subdirectories.

Specifications

Specification Status Comment
{{SpecName('File System API')}} {{Spec2('File System API')}} Draft of proposed API

This API has no official W3C or WHATWG specification.

Browser compatibility

{{ CompatibilityTable }}

Feature Chrome Firefox (Gecko) Internet Explorer Microsoft Edge Opera Safari (WebKit)
Basic support 13 {{ property_prefix("webkit") }} {{ CompatGeckoDesktop(50) }}[2] {{ CompatNo }} {{CompatNo}}[3] {{ CompatNo }} {{ CompatNo }}
removeRecursively() 13 {{ property_prefix("webkit") }} {{ CompatNo }}[1] {{ CompatNo }} {{ CompatNo }} {{ CompatNo }} {{ CompatNo }}
getFile() and getDirectory() 13 {{ property_prefix("webkit") }} {{ CompatGeckoDesktop(50) }}[2] {{ CompatNo }} {{ CompatNo }} {{ CompatNo }} {{ CompatNo }}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{ CompatNo }} 0.16 {{ property_prefix("webkit") }} {{ CompatGeckoDesktop(50) }}[2] {{ CompatNo }} {{ CompatNo }} {{ CompatNo }}
removeRecursively() {{ CompatNo }} 0.16 {{ property_prefix("webkit") }} {{ CompatNo }}[1] {{ CompatNo }} {{ CompatNo }} {{ CompatNo }}
getFile() and getDirectory() {{ CompatNo }} 0.16 {{ property_prefix("webkit") }} {{ CompatGeckoDesktop(50) }}[2] {{ CompatNo }} {{ CompatNo }} {{ CompatNo }}

[1] While the {{domxref("FileSystemDirectoryEntry.removeRecursively", "removeRecursively()")}} method exists in Firefox 50, all it does is immediately call the error callback with NS_ERROR_DOM_SECURITY_ERR.

[2] In Firefox, the error callback's parameter is a {{domxref("DOMError")}} rather than a {{domxref("FileError")}} object.

[3] Microsoft Edge implements the functionality of this interface within the WebKitEntry interface, which is what it calls {{domxref("FileSystemEntry")}}.

See also

Revision Source

<p>{{APIRef("File System API")}}{{Non-standard_header}}</p>

<p>The <strong><code>FileSystemDirectoryEntry</code></strong> interface of the <a href="/en-US/docs/Web/API/File_and_Directory_Entries_API">File and Directory Entries API</a> represents a directory in a file system. It provides methods which make it possible to access and manipulate the files in a directory, as well as to access the entries within the directory.</p>

<div class="note">
<p>Because this is a non-standard API, whose specification is not currently on a standards track, it's important to keep in mind that not all browsers implement it, and those that do may implement only small portions of it. Check the {{anch("Browser compatibility")}} section for details.</p>
</div>

<h2 id="basic_concepts" name="basic_concepts">Basic concepts</h2>

<p>You can create a new directory by calling {{domxref("FileSystemDirectoryEntry.getDirectory", "getDirectory()")}}. If you want to create subdirectories, create each child directory in sequence. If you try creating a directory using a full path that includes parent directories that do not exist yet, an error is returned. So create the hierarchy by recursively adding a new path after creating the parent directory.</p>

<h3 id="example" name="example">Example</h3>

<p>In the following code snippet, we create a directory called "Documents."</p>

<pre class="brush: js">
// Taking care of the browser-specific prefixes.
window.requestFileSystem&nbsp;&nbsp;=&nbsp;window.requestFileSystem&nbsp;||&nbsp;window.webkitRequestFileSystem;&nbsp;
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="Properties">Properties</h2>

<p><em>This interface has no properties of its own, but inherits properties from its parent interface, {{domxref("FileSystemEntry")}}.</em></p>

<h2 id="Methods">Methods</h2>

<p><em>This interface inherits methods from its parent interface, {{domxref("FileSystemEntry")}}.</em></p>

<dl>
 <dt>{{domxref("FileSystemDirectoryEntry.createReader", "createReader()")}}</dt>
 <dd>Creates a {{domxref("FileSystemDirectoryReader")}} object which can be used to read the entries in this directory.</dd>
 <dt>{{domxref("FileSystemDirectoryEntry.getDirectory", "getDirectory()")}}</dt>
 <dd>Returns a {{domxref("FileSystemDirectoryEntry")}} object representing a directory located at a given path, relative to the directory on which the method is called.</dd>
 <dt>{{domxref("FileSystemDirectoryEntry.getFile", "getFile()")}}</dt>
 <dd>Returns a {{domxref("FileSystemFileEntry")}} object representing a file located within the directory's hierarchy, given a path relative to the directory on which the method is called.</dd>
 <dt>{{domxref("FileSystemDirectoryEntry.removeRecursively", "removeRecursively()")}}</dt>
 <dd>Deletes a directory and all of its contents, including the contents of subdirectories.</dd>
</dl>

<h2 id="Specifications">Specifications</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>This API has no official W3C or WHATWG specification.</p>

<h2 id="Browser_compatibility" name="Browser_compatibility">Browser compatibility</h2>

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

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</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>{{ 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>{{ 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>{{ 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>Firefox Mobile (Gecko)</th>
   <th>IE&nbsp;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>{{ 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>{{ 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>{{ CompatGeckoDesktop(50) }}<sup>[2]</sup></td>
   <td>{{ CompatNo }}</td>
   <td>{{ CompatNo }}</td>
   <td>{{ CompatNo }}</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] While the {{domxref("FileSystemDirectoryEntry.removeRecursively", "removeRecursively()")}} method exists in Firefox 50, all it does is immediately call the error callback with <code>NS_ERROR_DOM_SECURITY_ERR</code>.</p>

<p>[2] In Firefox, the error callback's parameter is a {{domxref("DOMError")}} rather than a {{domxref("FileError")}} object.</p>

<p>[3] Microsoft Edge implements the functionality of this interface within the <code>WebKitEntry</code> interface, which is what it calls {{domxref("FileSystemEntry")}}.</p>

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="/en-US/docs/Web/API/File_and_Directory_Entries_API">File and Directory Entries API</a></li>
 <li><a href="/en-US/docs/Web/API/File_and_Directory_Entries_API/Introduction">Introduction to the File System API</a></li>
 <li>{{domxref("FileSystemDirectoryReader")}}</li>
 <li>{{domxref("FileSystemEntry")}}</li>
 <li>{{domxref("FileSystemFileEntry")}}</li>
</ul>
Revert to this revision