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 1125121 of FileSystemEntry

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

Revision Content

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

The FileSystemEntry interface of the File and Directory Entries API represents a single in a file system. The entry can be a file or a directory (directories are represented by the {{domxref("DirectoryEntry")}} interface. It includes methods for working with files—including copying, moving, removing, and reading files—as well as information about a file it points to—including the file name and its path from the root to the entry.

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 don't create FileSystemEntry objects directly. Instead, you will receive an object based on this interface through other APIs. This interface serves as a base class for the {{domxref("FileSystemFileEntry")}} and {{domxref("FileSystemDirectoryEntry")}} interfaces, which provide features specific to file system entries representing files and directories, respectively.

The FileSystemEntry interface includes methods that you would expect for manipulating files and directories, but it also includes a convenient method for obtaining the URL of the entry: toURL(). It also introduces a new URL scheme: filesystem:.

You can use the filesystem: scheme on Google Chrome to see all the files and folders that are stored in the origin of your app. Just use filesystem: scheme for the root directory of the origin of the app. For example, if your app is in https://www.html5rocks.com, open filesystem:https://www.html5rocks.com/temporary/ in a tab. Chrome shows a read-only list of all the files and folders stored the origin of your app.

Example

To see an example of how toURL() works, see the method description. The snippet below shows you how you can remove a file by name.

// Taking care of the browser-specific prefixes.
window.requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem; 

...

// Opening a file system with temporary storage
window.requestFileSystem(TEMPORARY, 1024*1024 /*1MB*/, function(fs) {
  fs.root.getFile('log.txt', {}, function(fileEntry) {
    
    fileEntry.remove(function() {
      console.log('File removed.');
    }, onError);
  
  }, onError);
}, onError); 

Properties

This interface provides the following properties.

{{domxref("FileSystemEntry.filesystem", "filesystem")}} {{ReadOnlyInline}}
A {{domxref("FileSystem")}} object representing the file system in which the entry is located.
{{domxref("FileSystemEntry.fullPath", "fullPath")}} {{ReadOnlyInline}}
A {{domxref("DOMString")}} object which provides the full, absolute path from the file system's root to the entry; it can also be thought of as a path which is relative to the root directory, prepended with a "/" character.
{{domxref("FileSystemEntry.isDirectory", "isDirectory")}} {{ReadOnlyInline}}
A {{jsxref("Boolean")}} which is true if the entry represents a directory; otherwise, it's false.
{{domxref("FileSystemEntry.isFile", "isFile")}} {{ReadOnlyInline}}
A Boolean which is true if the entry represents a file. If it's not a file, this value is false.
{{domxref("FileSystemEntry.name", "name")}} {{ReadOnlyInline}}
A {{domxref("DOMString")}} containing the name of the entry (the final part of the path, after the last "/" character).

Methods

This interface defines the following methods.

{{domxref("FileSystemEntry.copyTo", "copyTo()")}}
Copies the file or directory to a new location on the file system.
{{domxref("FileSystemEntry.getMetadata", "getMetadata()")}}
Obtains metadata about the file, such as its modification date and size.
{{domxref("FileSystemEntry.getParent", "getParent()")}}
Returns a {{domxref("FileSystemDirectoryEntry")}} representing the entry's parent directory.
{{domxref("FileSystemEntry.moveTo", "moveTo()")}}
Moves the file or directory to a new location on the file system, or renames the file or directory.
{{domxref("FileSystemEntry.remove", "remove()")}}
Removes the specified file or directory. You can only remove directories which are empty.
{{domxref("FileSystemEntry.toURL", "toURL()")}}
Creates and returns a URL which identifies the entry. This URL uses the URL scheme "filesystem:".

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)}}[1] {{CompatNo}} {{CompatVersionUnknown}}[2] {{CompatNo}} {{CompatNo}}
copyTo(), getMetadata(), getParent(), moveTo(), remove(), toURL() 13 {{property_prefix("webkit")}} {{CompatNo}} {{CompatNo}} {{CompatNo}} {{CompatNo}} {{CompatNo}}
filesystem: URL scheme 13 {{property_prefix("webkit")}} {{CompatNo}} {{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")}} {{CompatGeckoMobile(50)}}[1] {{CompatNo}} {{CompatNo}} {{CompatNo}}
copyTo(), getMetadata(), getParent(), moveTo(), remove(), toURL() {{CompatNo}} 0.16 {{property_prefix("webkit")}} {{CompatNo}} {{CompatNo}} {{CompatNo}} {{CompatNo}}
filesystem: URL scheme {{CompatNo}} 0.16 {{property_prefix("webkit")}} {{CompatNo}} {{CompatNo}} {{CompatNo}} {{CompatNo}}

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

[2] Microsoft Edge calls this interface WebKitEntry; in addition, it implements {{domxref("FileSystemFileEntry")}} and {{domxref("FileSystemDirectoryEntry")}} as part of this interface, instead of as separate interfaces which inherit from this one.

See also

Revision Source

<div>{{APIRef("File System API")}} {{non-standard_header}}</div>

<p>The <strong><code>FileSystemEntry</code></strong> interface of the File and Directory Entries API represents a single in a file system. The entry can be a file or a directory (directories are represented by the {{domxref("DirectoryEntry")}} interface. It includes methods for working with files—including copying, moving, removing, and reading files—as well as information about a file it points to—including the file name and its path from the root to the entry.</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" name="basic">Basic concepts</h2>

<p>You don't create <code>FileSystemEntry</code> objects directly. Instead, you will receive an object based on this interface through other APIs. This interface serves as a base class for the {{domxref("FileSystemFileEntry")}} and {{domxref("FileSystemDirectoryEntry")}} interfaces, which provide features specific to file system entries representing files and directories, respectively.</p>

<p>The <code>FileSystemEntry</code> interface includes methods that you would expect for manipulating files and directories, but it also includes a convenient method for obtaining the URL of the entry: <code><a href="#toURL">toURL()</a></code>. It also introduces a new URL scheme: <code>filesystem:</code>.</p>

<p>You can use the <code>filesystem:</code> scheme on Google Chrome to see all the files and folders that are stored in the origin of your app. Just use <code>filesystem:</code> scheme for the root directory of the origin of the app. For example, if your app is in <code><a href="https://www.html5rocks.com" rel="freelink">https://www.html5rocks.com</a></code>, open<code> filesystem:<a href="https://www.html5rocks.com/temporary/" rel="freelink">https://www.html5rocks.com/temporary/</a></code> in a tab. Chrome shows a read-only list of all the files and folders stored the origin of your app.</p>

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

<p>To see an example of how <code>toURL()</code> works, see the <a href="#toURL">method description</a>. The snippet below shows you how you can remove a file by name.</p>

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

...

// Opening a file system with temporary storage
window.requestFileSystem(TEMPORARY, 1024*1024 /*1MB*/, function(fs) {
  fs.root.getFile('log.txt', {}, function(fileEntry) {
    
    fileEntry.remove(function() {
      console.log('File removed.');
    }, onError);
  
  }, onError);
}, onError); </pre>

<h2 id="Properties">Properties</h2>

<p><em>This interface provides the following properties.</em></p>

<dl>
 <dt>{{domxref("FileSystemEntry.filesystem", "filesystem")}} {{ReadOnlyInline}}</dt>
 <dd>A {{domxref("FileSystem")}} object representing the file system in which the entry is located.</dd>
 <dt>{{domxref("FileSystemEntry.fullPath", "fullPath")}} {{ReadOnlyInline}}</dt>
 <dd>A {{domxref("DOMString")}} object which provides the full, absolute path from the file system's root to the entry; it can also be thought of as a path which is relative to the root directory, prepended with a "/" character.</dd>
 <dt>{{domxref("FileSystemEntry.isDirectory", "isDirectory")}} {{ReadOnlyInline}}</dt>
 <dd>A {{jsxref("Boolean")}} which is <code>true</code> if the entry represents a directory; otherwise, it's <code>false</code>.</dd>
 <dt>{{domxref("FileSystemEntry.isFile", "isFile")}} {{ReadOnlyInline}}</dt>
 <dd>A Boolean which is <code>true</code> if the entry represents a file. If it's not a file, this value is <code>false</code>.</dd>
 <dt>{{domxref("FileSystemEntry.name", "name")}} {{ReadOnlyInline}}</dt>
 <dd>A {{domxref("DOMString")}} containing the name of the entry (the final part of the path, after the last "/" character).</dd>
</dl>

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

<p><em>This interface defines the following methods.</em></p>

<dl>
 <dt>{{domxref("FileSystemEntry.copyTo", "copyTo()")}}</dt>
 <dd>Copies the file or directory to a new location on the file system.</dd>
 <dt>{{domxref("FileSystemEntry.getMetadata", "getMetadata()")}}</dt>
 <dd>Obtains metadata about the file, such as its modification date and size.</dd>
 <dt>{{domxref("FileSystemEntry.getParent", "getParent()")}}</dt>
 <dd>Returns a {{domxref("FileSystemDirectoryEntry")}} representing the entry's parent directory.</dd>
 <dt>{{domxref("FileSystemEntry.moveTo", "moveTo()")}}</dt>
 <dd>Moves the file or directory to a new location on the file system, or renames the file or directory.</dd>
 <dt>{{domxref("FileSystemEntry.remove", "remove()")}}</dt>
 <dd>Removes the specified file or directory. You can only remove directories which are empty.</dd>
 <dt>{{domxref("FileSystemEntry.toURL", "toURL()")}}</dt>
 <dd>Creates and returns a URL which identifies the entry. This URL uses the URL scheme <code>"filesystem:"</code>.</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>

<div>{{CompatibilityTable}}</div>

<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>[1]</sup></td>
   <td>{{CompatNo}}</td>
   <td>{{CompatVersionUnknown}}<sup>[2]</sup></td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
  <tr>
   <td><code>copyTo()</code>, <code>getMetadata()</code>, <code>getParent()</code>, <code>moveTo()</code>, <code>remove()</code>, <code>toURL()</code></td>
   <td>13 {{property_prefix("webkit")}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
  <tr>
   <td><code>filesystem:</code> URL scheme</td>
   <td>13 {{property_prefix("webkit")}}</td>
   <td>{{CompatNo}}</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 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>{{CompatGeckoMobile(50)}}<sup>[1]</sup></td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
  <tr>
   <td><code>copyTo()</code>, <code>getMetadata()</code>, <code>getParent()</code>, <code>moveTo()</code>, <code>remove()</code>, <code>toURL()</code></td>
   <td>{{CompatNo}}</td>
   <td>0.16 {{property_prefix("webkit")}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
  <tr>
   <td><code>filesystem:</code> URL scheme</td>
   <td>{{CompatNo}}</td>
   <td>0.16 {{property_prefix("webkit")}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

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

<p>[2] Microsoft Edge calls this interface <code>WebKitEntry</code>; in addition, it implements {{domxref("FileSystemFileEntry")}} and {{domxref("FileSystemDirectoryEntry")}} as part of this interface, instead of as separate interfaces which inherit from this one.</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("FileSystemFileEntry")}} and {{domxref("FileSystemDirectoryEntry")}} are based on <code>FileSystemEntry</code>.</li>
</ul>
Revert to this revision