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.

Entry

Esta traducción está incompleta. Por favor, ayuda a traducir este artículo del inglés.

No estándar
This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

La interfaz de acceso de la FileSystem API representa una entrada al sistema de archivos. La entrada puede ser un archivo o directorio. La interfaz incluye métodos para trabajar con archivos- incluyendo copiado, movimiento, eliminacion y lectura de archivos- así como información del archivo al cual apunta- incluyendo su nombre y la ruta desde la raíz hasta la entrada.

Sobre este documento

Este documento fue actualizado por última vez en Marzo 2 de 2011 y trata las especificaciones W3C(Borrador en desarrollo) bocetado en Abril 19 de 2011.

La especificacion está mas o menos abandonada al no haber conseguido tracción significativa.

Conceptos Básicos

The Entry interface includes methods that you would expect for manipulating files and directories, but it also include a really handy method for getting a 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://ww.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); 

Method overview

void getMetadata (in MetadataCallback successCallback, in optional ErrorCallback errorCallback);
void moveTo (in DirectoryEntry parent, optional DOMString newName, in optional EntryCallback successCallback, in optional ErrorCallback errorCallback);
void copyTo (in DirectoryEntry parent, in optional DOMString newName, in optional EntryCallback successCallback, in optional ErrorCallback errorCallback);
void toURL (in optional DOMString mimeType);
void remove (in VoidCallback successCallback, in optional ErrorCallback errorCallback);
void getParent (in EntryCallback successCallback, in optional ErrorCallback errorCallback);

Attributes

Attribute Type Description
filesystem readonly FileSystem The file system where the entry resides.
fullPath readonly DOMString The full absolute path from the root to the entry.

An absolute path is a relative path from the root directory, prepended with a '/'.

isDirectory readonly boolean True if the entry is a directory.
isFile readonly boolean True if the entry is a file.
name readonly DOMString The name of the entry, excluding the path leading to it.

Methods

getMetadata()

Look up last modification date of the entry.

void getMetadata (
  in MetadataCallback ErrorCallback
);
Parameter
successCallback
A callback that is called with the time of the last modification.
errorCallback
A callback that is called when errors happen.
Returns
void

moveTo()

Move an entry to a different location on the file system. Moving a file over an existing file replaces that existing file. A move of a directory on top of an existing empty directory replaces that directory.

You can also use this method for renaming files. You can keep it in the same location and then define the newName parameter.

You cannot do the following:

  • Move a directory inside itself or to any child at any depth
  • Move an entry into its parent if a name different from its current one isn't provided
  • Move a file to a path occupied by a directory or move a directory to a path occupied by a file
  • Move any element to a path occupied by a directory that is not empty.
void moveTo (
  in DirectoryEntry parent, optional DOMString newName, optional EntryCallback successCallback, optional ErrorCallback errorCallback
);
Parameter
parent
The directory to which to move the entry.
newName
The new name of the entry. If you do not specify a name, the browser preserves the entry's current name.
successCallback
A callback that is called when the file or directory has been successfully moved.
errorCallback
An optional callback that is called only when errors happen.
Returns
void

copyTo()

Copy an entry to a different location on the file system. You cannot copy an entry inside itself if it is a directory, nor can you copy it into its parent if you don't provide a new name. Directory copies are always recursive—that is, they copy all contents of the directory. You cannot change this behavior. Files are simply duplicated.

void copyTo (
  in DirectoryEntry parent, optional DOMString newName, optional EntryCallback successCallback, optional ErrorCallback errorCallback
);
Parameter
parent
The directory where you want the entry to move to.
newName
The new name of the entry. If you do not specify a name, the browser preserves the entry's current name.
successCallback
A callback that is called when the file or directory has been successfully copied.
errorCallback
An optional callback that is called only when errors happen.
Returns
void

toURL()

Returns a URL that can be used to identify this entry. It exposes a new URL scheme—filesystem:—that you can use to fill src or href attributes. For example, if you wanted to display an image and have its fileEntry, calling toURL() gives you the image file's file system URL. You get something like: filesystem:https://example.com/temporary/lolcat.png.

The following is an example:

var img = document.createElement('img'); 
// Get the URL of the entry, which returns: filesystem:https://example.com/temporary/lolcat.png 
img.src = fileEntry.toURL(); 
document.body.appendChild(img);

The file system URL does not expire. Because the method describes a location on disk, the URL is valid for as long as that location exists. You can delete the file and recreate it, and it's all good.

You can supply the mimeType to simulate the optional MIME-type header associated with HTTP downloads.

DOMString toURL (
  in optional DOMString mimeType
);
Parameter
mimeType
The MIME type that you want to be used to interpret the file when it is loaded through this URL.
Returns
DOMString

remove()

Deletes a file or directory. You cannot delete an empty directory or the root directory of a file system. If you want to remove an empty directory, use removeRecursively() instead.

void remove (
  in VoidCallback successCallback, optional ErrorCallback errorCallback
);
Parameter
successCallback
A callback that is called when the file is successfully deleted.
errorCallback
An optional callback that is called only when errors happen.
Returns
void

getParent()

Look up the parent DirectoryEntry containing the entry. If this entry is the root of its file system, then the parent is itself.

void getParent (
 in EntryCallback successCallback, optional ErrorCallback errorCallback
);
Parameter
parent
The directory where you want to move the entry.
newName
The new name of the entry. If you do not specify a name, the browser preserves the entry's current name.
successCallback
A callback that is called when the look-up entry is successful.
errorCallback
An optional callback that is called when errors happen.
Returns
void

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 13webkit Not supported Not supported Not supported Not supported
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support Not supported 0.16webkit Not supported Not supported Not supported Not supported

See also

Etiquetas y colaboradores del documento

 Colaboradores en esta página: chronosx7
 Última actualización por: chronosx7,